Ternary filters
Overview
Ternary filters allow you to easily create a select filter which has three states - usually true, false and blank. To filter a column named is_admin
to be true
or false
, you may use the ternary filter:
use Filament\Tables\Filters\TernaryFilter;
TernaryFilter::make('is_admin')
Using a ternary filter with a nullable column
Another common pattern is to use a nullable column. For example, when filtering verified and unverified users using the email_verified_at
column, unverified users have a null timestamp in this column. To apply that logic, you may use the nullable()
method:
use Filament\Tables\Filters\TernaryFilter;
TernaryFilter::make('email_verified_at')
->nullable()
Customizing the column used by a ternary filter
The column name used to scope the query is the name of the filter. To customize this, you may use the attribute()
method:
use Filament\Tables\Filters\TernaryFilter;
TernaryFilter::make('verified')
->nullable()
->attribute('status_id')