SQLSTATE[HY000]: General error: 1364 Field 'slug' doesn't have a default value

I tried to create a new tag in Filament, this is my Filament tag form:
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state)))
->unique(ignoreRecord: true)
->required()
->maxLength(100),
Forms\Components\TextInput::make('slug')->hidden(),
]);

}
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\TextInput::make('name')
->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state)))
->unique(ignoreRecord: true)
->required()
->maxLength(100),
Forms\Components\TextInput::make('slug')->hidden(),
]);

}
I got the error: SQLSTATE[HY000]: General error: 1364 Field 'slug' doesn't have a default value anyone knows why the callback isn't being triggered or the generated slug is not being saved?
1 Reply
Dennis Koch
Dennis Koch6mo ago
Hidden fields don't send data. Use the mutateDataBeforeCreate hook.
Want results from more Discord servers?
Add your server