Skip to main content

Introduction

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_featured to be true or false, you may use the ternary filter:

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:

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:

Customizing the ternary filter option labels

You may customize the labels used for each state of the ternary filter. The true option label can be customized using the trueLabel() method. The false option label can be customized using the falseLabel() method. The blank (default) option label can be customized using the placeholder() method:

Customizing how a ternary filter modifies the query

You may customize how the query changes for each state of the ternary filter, use the queries() method:

Filtering soft-deletable records

The TrashedFilter can be used to filter soft-deleted records. It is a type of ternary filter that is built-in to Filament. You can use it like so: