Nova filters are simple classes that allow you to scope your Nova index queries with custom conditions.
nova:filter
Artisan command. By default, Nova will place newly generated filters in the app/Nova/Filters
directory:
apply
and options
. The apply
method is responsible for modifying the underlying Eloquent query to achieve the desired filter state, while the options
method defines the “values” the filter may have. Let’s take a look at an example UserType
filter:
options
method should return an array of keys and values. The array’s keys will be used as the “human-friendly” text that will be displayed in the Nova UI, while the array’s values will be passed into the apply
method as the $value
argument. This filter defines two possible values: admin
and editor
.
As you can see in the example above, you may leverage the incoming $value
to modify your query, and the apply
method should return the modified query instance.
nova:filter --boolean
Artisan command. By default, Nova will place newly generated filters in the app/Nova/Filters
directory:
apply
and options
. The apply
method is responsible for modifying the Eloquent query to achieve the desired filter state, while the options method defines the “values” the filter may have.
When building boolean filters, the $value
argument passed to the apply
method is an associative array containing the boolean value of each of your filter’s options. Let’s take a look at an example UserType
filter:
options
method should return an array of keys and values. The array’s keys will be used as the “human-friendly” text that will be displayed in the Nova UI. The array’s values will be passed into the apply
method as the $value
argument. This filter defines two possible values: admin
and editor
.
As you can see in the example above, you may leverage the incoming $value
to modify your query. The apply
method should return the modified query instance.
nova:filter --date
Artisan command. By default, Nova will place newly generated filters in the app/Nova/Filters
directory:
apply
. The apply
method is responsible for modifying the query to achieve the desired filter state.
When building date filters, the $value
argument passed to the apply
method is the string representation of the selected date. Let’s take a look at an example BirthdayFilter
filter:
$value
to modify your query. The apply
method should return the modified query instance.
name
property on the filter class:
name
method on the filter class:
default
method on the filter class:
key
method of the filter so that Nova can uniquely identify this instance of the filter if multiple instances of this filter exist on the page. Let’s take a look at an example TimestampFilter
filter: