© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
2 replies
Millio

Using "Select" form component with field cast to boolean

I have a nullable boolean field called "approved" which has 3 options true (approved) , false (rejected) and null (undecided). In my model, the approved field is cast to a boolean.
    protected $casts= [
        'approved' => 'boolean',
    ];
    protected $casts= [
        'approved' => 'boolean',
    ];


I can't seem to get this working with the filament 'edit' form though...
                Forms\Components\Select::make('approved')
                    ->options([
                        true => 'Approved',
                        false => 'Rejected'
                    ])->nullable()
                Forms\Components\Select::make('approved')
                    ->options([
                        true => 'Approved',
                        false => 'Rejected'
                    ])->nullable()


This correctly saves the value to database but on refreshing the edit page it always shows "Pick an option" instead of the current "Approved" / "Rejected" value from the database.

If I change the options from true to 'true' and false to 'false' (with single quotation marks) it correctly DISPLAYS the current database value but now saving does not change the values in database... (I've also tried with 1/0 and '1'/ '0' but that doesn't seem to work either).

Main reason I'm using Select instead of Toggle is to be able to easier differentiate between null and false. Removing the cast from the model does work but that causes other issues in other parts of the code.

Thanks
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Using $form->schema with Select field's createOptionForm
FilamentFFilament / ❓┊help
3y ago
Edit Select form component
FilamentFFilament / ❓┊help
2y ago
Filament Select Form Component
FilamentFFilament / ❓┊help
2y ago
How to properly use a boolean Select field.
FilamentFFilament / ❓┊help
3y ago