medalink/laravel-reflects-constants 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

medalink/laravel-reflects-constants

Composer 安装命令:

composer require medalink/laravel-reflects-constants

包简介

A small helper package that aids in the retrieval of class constants of models in laravel.

README 文档

README

A small helper package that aids in the retrieval of class constants of models.

composer require medalink/laravel-reflects-constants

How to use

Let's assume you have a class with defined constants for different types.

<?php
class ProductInformation
{
    use \Medalink\Reflects\Constants;

    /**
    * Optional constant blacklist, anything in here will be filtered
    */
    public $reflectedConstantsBlacklist = [
        'TEST',
    ];

    const TYPE_OVERVIEW = 'OVERVIEW';
    const TYPE_SAFETY = 'SAFETY';
    const TYPE_WARRANTY = 'WARRANTY';
    const TYPE_PRODUCT_INFO = 'PRODUCT_INFO';
    const TEST = 'TEST';
}

This package will allow you to return these constants as a human readable array. This is most useful when using this data in various places through your application. Let's take a look at using this package to help a factory choose a random type.

$factory->define(ProductInformation::class, function (Faker $faker) {
    return [
        'type' => $faker->randomElement(ProductInformation::getReflectedConstants('TYPE_')),
    ];
});

The resulting array would look like this:

$types = ProductInformation::getReflectedConstants('TYPE_');

$types = [
    'Overview',
    'Safety',
    'Warranty',
    'Product Info'
];

Let's take a look at using this to populate a laravel nova options dropdown.

Select::make('Type')
    ->options(ProductInformation::getReflectedConstants('TYPE_'))
    ->sortable(),

The getReflectedConstants supports a blacklist, a prefix, returning the prefix with the constant name, and a human readable toggle. Take a look at the source for more details on how to use these features.

统计信息

  • 总下载量: 3.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-01-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固