1. Go to this page and download the library: Download carlin/laravel-dict library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
namespace App\Enums;
use Carlin\LaravelDict\Dict;
use BenSampo\Enum\Enum;
class BaseEnum extends Enum {
public static function getDescription(mixed $value): string
{
return Dict::getDescription(static::class, $value) ?? parent::getDescription($value);
}
public static function descriptions(): array
{
return Dict::getEnums(static::class);
}
}
namespace App\Enums;
use Carlin\LaravelDict\Attributes\EnumClass;
use Carlin\LaravelDict\Attributes\EnumProperty;
#[EnumClass(
__CLASS__, //枚举类名
'布尔整型枚举', //枚举描述
'webApi', //枚举分组
[
'test'=>1 //业务拓展字段(选填)
]
)] //枚举类注解
class BoolIntEnums extends BaseEnum
{
//#[EnumProperty('是', ['test'=>2])] //业务拓展字段(选填)
#[EnumProperty('是', ['test'=>2])]
public const TRUE = 1;
//#[EnumProperty('否', ['test'=>1])]
#[EnumProperty('否')]
public const FALSE = 0;
}