定制 jundayw/laravel-enumeration 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

jundayw/laravel-enumeration

最新稳定版本:v0.6.0

Composer 安装命令:

composer require jundayw/laravel-enumeration

包简介

The Laravel Enumeration.

README 文档

README

命令行下, 执行 composer 命令安装:

composer require jundayw/laravel-enumeration

命令行

发布配置文件

php artisan vendor:publish --tag=enumeration

生成

php artisan make:enumeration Test

使用方法

枚举配置

namespace App\Enums;

use Jundayw\LaravelEnumeration\Annotation\Attributes;
use Jundayw\LaravelEnumeration\Concerns\HasEnumeration;
use Jundayw\LaravelEnumeration\Contracts\Enumeration;

enum Test: string implements Enumeration
{
    use HasEnumeration;

    #[Attributes(attribute: '正常')]
    case NORMAL = 'NORMAL';
    #[Attributes(attribute: '禁用')]
    case DISABLE = 'DISABLE';
    #[Attributes(attribute: 'Attribute')]
    case NAME = 'VALUE';

}

模型配置

namespace App\Models;

use App\Enums\Test;
use Illuminate\Database\Eloquent\Model;

class Manager extends Model
{
    /**
     * @var string[]
     */
    protected $casts = [
        'state' => Test::class,
    ];

}

枚举集合

use App\Enums\Test;

dd(Test::cases());
dd(Test::values());

修改器

use App\Enums\Test;
use App\Models\Manager;

$manager = new Manager();
$manager->state = Test::NAME;
$manager->state = Test::from('VALUE');
$manager->state = Test::valueOf('value')->getDeclaringClass();
$manager->state = Test::valueOf('VALUE')->getDeclaringClass();
$manager->state = Test::valueOf('VALUE')->getDeclaringClass()->value;

拾取器

use App\Enums\Test;
use App\Models\Manager;

$manager = (new Manager())->find(1);;
dd($manager->state);

枚举方法集合

use App\Enums\Test;
use Jundayw\LaravelEnumeration\Annotation\Attributes;

dd([
    // Test[]
    Test::cases(),
    // string
    Test::NAME->name,
    // string
    Test::NAME->getName(),
    // string
    Test::NAME->value,
    // string
    Test::NAME->getValue(),
    // mixed
    Test::NAME->getAttribute(),
    // array
    Test::NAME->toArray(),
    // string
    Test::NAME->toJson(),
    // Attributes[]
    Test::values(),
    // string
    Test::valueOf('NAME', Test::NAME)->name,
    // string
    Test::valueOf('NAME', Test::NAME)->getName(),
    // string
    Test::valueOf('NAME', Test::NAME)->value,
    // string
    Test::valueOf('NAME', Test::NAME)->getValue(),
    // mixed
    Test::valueOf('NAME', Test::NAME)->getAttribute(),
    // string
    Test::valueOf('value')->name,
    // string
    Test::valueOf('value')->getName(),
    // string
    Test::valueOf('value')->value,
    // string
    Test::valueOf('value')->getValue(),
    // mixed
    Test::valueOf('value')->getAttribute(),
    // Test
    Test::valueOf('value')->getDeclaringClass(),
    // string
    Test::valueOf('value')->getDeclaringClass()->name,
    // string
    Test::valueOf('value')->getDeclaringClass()->getName(),
    // string
    Test::valueOf('value')->getDeclaringClass()->value,
    // string
    Test::valueOf('value')->getDeclaringClass()->getValue(),
    // mixed
    Test::valueOf('value')->getDeclaringClass()->getAttribute(),
]);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-08-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固