# Make
Extends
Select
* has the same features
Works the same as the Select field, but takes an Enum as options.
Model attributes require Enum Cast.
use MoonShine\Fields\Enum; //... public function fields(): array{ return [ Enum::make('Status') ->attach(StatusEnum::class) ];} //...
# Displaying values
toString
The toString()
method implemented in Enum
allows you to set the output value.
namespace App\Enums; enum StatusEmun: 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', }; }}
getColor
If Enum implements the getColor()
method,
then the preview field will appear as an icon of a certain color.
Available colors:
primary secondary success warning error info
purple pink blue green yellow red gray
namespace App\Enums; enum StatusEmun: 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', }; }}