filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
17.65k stars 2.76k forks source link

Should Boolean Column Type Treat Null as False? #947

Closed intrepidws closed 2 years ago

intrepidws commented 2 years ago

Package

filament/filament

Package Version

v2.6.3

Laravel Version

v8.76.2

Livewire Version

v2.8.2

PHP Version

PHP 8.0.13

Bug description

I will occasionally use a datetime field in place of a boolean field, so that I can easily track when the change was made. For instance, if I have a product that can be archived, I will use a datetime field called archived_at rather than a boolean field called archived. So the "false" state for this type of field is null.

My use case is that I'd like to display an icon in the table view to show whether or not the product is archived. My initial instinct was to use the boolean field type as such:

Tables\Columns\BooleanColumn::make('archived_at')
    ->trueIcon('heroicon-o-badge-check')
    ->falseIcon('heroicon-o-x-circle'),

However, Filament doesn't recognize the null state as false so the icon for false never shows. I have had to use the following code instead:

Tables\Columns\IconColumn::make('archived_at')
    ->options([
        'heroicon-o-x-circle',
        'heroicon-o-check-circle' => fn ($state): bool => ! is_null($state),
    ])

While this works fine, it does seem that it would be nice if the boolean field type either recognized null as false or perhaps adding a nullIcon() method.

Steps to reproduce

No response

Relevant log output

No response

danharrin commented 2 years ago

No, null is used for not displaying the icon at all. The solution you gave is correct :)