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?
3 Replies
wyChoong
wyChoong16mo ago
you probably don't need the ->enum ?
cheesegrits
cheesegrits16mo ago
Out of interest, are you seeing any Livewire errors on the page? I've seen some Livewire weirdness when casting model attributes to custom classes.
lordgandal
lordgandalOP16mo ago
with or without
->enum
->enum
it still same no errors ok. the problem is solved there is nothing wrong in using an enum class. it's just that the data 'type' apparently doesn't exist in my model.
Want results from more Discord servers?
Add your server