#ToggleButton state return string

11 messages · Page 1 of 1 (latest)

glossy pewter
#

Inside the protected function:

handleRecordUpdate(Model $record, array $data): Model
 {
 dd($data);
```php

returns "1" or "0".

When it should be null, 0 or 1.

```php
ToggleButtons::make('test')
    ->label('Test')
    ->inline()
    ->boolean(),
balmy patrolBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

rocky barn
#

Well, null, true or false isn’t an actual Boolean, right?

#

It can’t be a bool with 3 options.

glossy pewter
#

If I need to store null, true or false what would be the best option?

rocky barn
#

But just doesn’t make sense to me to be null, true or false, just default to false.

glossy pewter
#

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🥲

rocky barn
#

So just set the default state of the checkbox to false.