store/app/Traits/ProvidesEnumOptions.php

34 lines
694 B
PHP

<?php
namespace App\Traits;
trait ProvidesEnumOptions
{
public static function options(): array
{
return collect(static::cases())
->mapWithKeys(fn ($case) => [
$case->value => $case->label(),
])
->all();
}
public static function selectOptions(): array
{
return collect(static::cases())
->map(fn ($case) => [
'value' => $case->value,
'label' => $case->label(),
])
->all();
}
/**
* @return list<string>
*/
public static function values(): array
{
return array_column(static::cases(), 'value');
}
}