ToggleButton state return string

Inside the protected function:
handleRecordUpdate(Model $record, array $data): Model
{
dd($data);
handleRecordUpdate(Model $record, array $data): Model
{
dd($data);
php returns "1" or "0". When it should be null, 0 or 1.
ToggleButtons::make('test')
->label('Test')
->inline()
->boolean(),
ToggleButtons::make('test')
->label('Test')
->inline()
->boolean(),
8 Replies
awcodes
awcodes2mo ago
Well, null, true or false isn’t an actual Boolean, right? It can’t be a bool with 3 options.
Daniel Reales
Daniel RealesOP2mo ago
If I need to store null, true or false what would be the best option?
awcodes
awcodes2mo ago
In my opinion, a select.
awcodes
awcodes2mo ago
Could do a toggle button with a null option too. If it’s about UI. https://filamentphp.com/docs/3.x/forms/fields/toggle-buttons
awcodes
awcodes2mo ago
But just doesn’t make sense to me to be null, true or false, just default to false.
Daniel Reales
Daniel RealesOP2mo ago
Good to know. Thanks for your advice. It really makes sense to use a ToggleButtons default to null and 0 , 1 for boolean I have an API whose validation is ['required', 'boolean'], or ['boolean']. If I leave it as a checkbox and it is not checked it is null, but it is actually required as false🥲
awcodes
awcodes2mo ago
So just set the default state of the checkbox to false.
Daniel Reales
Daniel RealesOP2mo ago
Perfect, thank you very much!

Did you find this page helpful?