Основы
Наследует Select.
* имеет те же возможности.
Работает так же, как поле Select
, но принимает Enum в качестве опций.
use MoonShine\UI\Fields\Enum; Enum::make('Status') ->attach(StatusEnum::class)
Атрибуты модели требуют Enum Cast.
Отображение значений
toString
Метод toString()
, реализованный в Enum, позволяет установить выводимое значение.
namespace App\Enums; enum StatusEnum: string{ case NEW = 'new'; case DRAFT = 'draft'; case PUBLIC = 'public'; public function toString(): ?string { return match ($this) { self::NEW => 'New', self::DRAFT => 'Draft', self::PUBLIC => 'Public', }; }}
Цвет
Если Enum реализует метод getColor()
, то поле в режиме "preview" будет отображаться как иконка определенного цвета.
Доступные цвета:
primary secondary success warning error info
purple pink blue green yellow red gray
namespace App\Enums; enum StatusEnum: string{ case NEW = 'new'; case DRAFT = 'draft'; case PUBLIC = 'public'; public function getColor(): ?string { return match ($this) { self::NEW => 'info', self::DRAFT => 'gray', self::PUBLIC => 'success', }; }}