how can I hide a form field which is $fillable in the model.

In my form, I have a field called department_id and I want to make it hidden() as I have another field called department_name which is displaying but disabled(). While doing so I'm getting this error "SQLSTATE[HY000]: General error: 1364 Field 'department_id' doesn't have a default value".

Upon exploring this I got this "❓┊helpSetting a default value for hidden fields" but I'm so sorry I don't know how I can use this
mutateFormDataBeforeCreate() function in my case.


TextInput::make('department_id')->label('Department')->hidden(), TextInput::make('department_name')->label('Department')->disabled(),
Discord
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
Solution
Forms\Components\Select::make('department_id')
    ->relationship('department', 'name')
    ->required()


should do it for you
Was this page helpful?