lordgandal
lordgandal
FFilament
Created by lordgandal on 8/15/2023 in #❓┊help
The option using enums on the edit page is not automatically selected after created
I already follow the instruction in here: https://filamentphp.com/docs/3.x/support/enums#overview but when editing record. the select always at "Select an option" this is my enum class
enum CustomerType: string implements HasLabel
{
case GUARDIAN = 'guardian';
case EMPLOYEE = 'employee';
case TEACHER = 'teacher';

public function getLabel(): ?string
{
return match ($this) {
self::GUARDIAN => trans('guardian'),
self::EMPLOYEE => trans('employee'),
self::TEACHER => trans('teacher'),
};
}
}
enum CustomerType: string implements HasLabel
{
case GUARDIAN = 'guardian';
case EMPLOYEE = 'employee';
case TEACHER = 'teacher';

public function getLabel(): ?string
{
return match ($this) {
self::GUARDIAN => trans('guardian'),
self::EMPLOYEE => trans('employee'),
self::TEACHER => trans('teacher'),
};
}
}
in the model i added this
protected $casts = [
'type' => CustomerType::class,
];
protected $casts = [
'type' => CustomerType::class,
];
and in resource i added this in form() method:
Select::make('type')
->options(CustomerType::class)
->enum(CustomerType::class)
->required()
->label(trans('customer_type')),
Select::make('type')
->options(CustomerType::class)
->enum(CustomerType::class)
->required()
->label(trans('customer_type')),
is something missing?
7 replies