FilamentF
Filament3y ago
Finn

Setting a default value for hidden fields

I have model which stores the user_id of the person who created each record. I don't want the user to see this field when interacting with the form - it should all happen behind the scenes.

The issue is that when I use:
Forms\Components\TextInput::make('user_id')
  ->default(auth()->user()->id)
  ->hidden(),

I get an SQL error SQLSTATE[HY000]: General error: 1364 Field 'user_id' doesn't have a default value.
Anyone know a solution for this?
Was this page helpful?