Rom*_*LTU 3 php enums laravel php-8.1
我的枚举必须具有用于翻译目的的附加方法:
<?php
declare(strict_types=1);
namespace App\Enums;
enum GenderEnum: string
{
case MALE = 'male';
case FEMALE = 'female';
public function trans(): string
{
return trans('enums.' . $this->value);
}
}
Run Code Online (Sandbox Code Playgroud)
这个方法是反式的,它会在所有枚举中重复,我怎样才能避免重复?我无法使用枚举中的特征来扩展它。
| 归档时间: |
|
| 查看次数: |
6815 次 |
| 最近记录: |