Enum is cast when creating but not editing

I have the following model (simplified)
class Config extends Model
{
protected $casts = [
'config_type' => ConfigType::class,
];
}
class Config extends Model
{
protected $casts = [
'config_type' => ConfigType::class,
];
}
and the following form resource
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('config_type')
->required()
->default(ConfigType::MAPPER)
->live()
->enum(ConfigType::class)
->options(ConfigType::class),
Forms\Components\Fieldset::make()
->statePath('config')
->schema(fn (Forms\Get $get) =>
dd($get('config_type')) // The problem is here
]);
}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Select::make('config_type')
->required()
->default(ConfigType::MAPPER)
->live()
->enum(ConfigType::class)
->options(ConfigType::class),
Forms\Components\Fieldset::make()
->statePath('config')
->schema(fn (Forms\Get $get) =>
dd($get('config_type')) // The problem is here
]);
}
In the above example, when I create a new Config, the $get('config_type') call returns and ConfigType enum as expected However, when I edit the resource, the same call returns a string (with the value of the enum) instead of an enum object as expected. Am I doing something wrong or is this just how filament works?
3 Replies
コック
コック3d ago
This code defaults to an Object , but I think it sets a Key if selected.
toeknee
toeknee6h ago
PAss in the options too, what happens then? i.e. ->options(RiskGrade::class) ->enum(RiskGrade::class),

Did you find this page helpful?