27 lines
547 B
PHP
27 lines
547 B
PHP
<?php
|
|
|
|
namespace App\Traits;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
trait EnumOptions
|
|
{
|
|
public static function options(): array
|
|
{
|
|
$cases = static::cases();
|
|
$options = [];
|
|
foreach ($cases as $case) {
|
|
$label = $case->name;
|
|
if (Str::contains($label, '_')) {
|
|
$label = Str::replace('_', ' ', $label);
|
|
}
|
|
$options[] = [
|
|
'value' => $case->value,
|
|
'label' => Str::title($label),
|
|
];
|
|
}
|
|
|
|
return $options;
|
|
}
|
|
}
|