© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
60 replies
leoPascal

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(),
  TextInput::make('department_id')->label('Department')->hidden(),
                    TextInput::make('department_name')->label('Department')->disabled(),
Discord
Discord - A New Way to Chat with Friends & Communities
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()
Forms\Components\Select::make('department_id')
    ->relationship('department', 'name')
    ->required()


should do it for you
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements
Next page

Similar Threads

How can I hide a field on the edit form?
FilamentFFilament / ❓┊help
3y ago
how can I hide a form field in first repeater
FilamentFFilament / ❓┊help
3y ago
Hide field in form
FilamentFFilament / ❓┊help
2y ago
how to hide a form field conditionally?
FilamentFFilament / ❓┊help
3y ago