Learn how to build custom filters for your Nova resources.
nova:custom-filter
Artisan command. By default, all new filters will be placed in the nova-components
directory of your application. When generating a filter using the nova:custom-filter
command, the filter name you pass to the command should follow the Composer vendor/package
format. So, if we were building an age-range filter, we might run the following command:
composer.json
file. All custom filters are registered with your application as a Composer “path” repository.
Nova filters include all of the scaffolding necessary to build your filter. Each filter even contains its own composer.json
file and is ready to be shared with the world on GitHub or the source control provider of your choice.
filters
method. This method returns an array of filters available to the resource. To register your filter, add your filter to the array of filters returned by this method:
make
method to instantiate your filter:
make
method will be passed to the constructor of your filter.
age-range
filter as an example, the filter class will be located at src/AgeRange.php
.
The filter’s service provider is also located within the src
directory of the filter, and is registered in your filter’s composer.json
file so that it will be auto-loaded by the Laravel framework.
resources/js/components/Filter.vue
Vue component. This component contains the template and logic for your filter when it is displayed in the filter dropdown menu. By default, the component displays a simple select
filter component, along with the needed code for updating the filter’s state.
resources/js
and resources/css
directories are generated for you. These directories contain your filter’s JavaScript and CSS.
resources/js/filter.js
file. You are free to modify this file or register additional components here as needed.webpack.mix.js
file, which is generated when Nova creates your filter. You may build your filter using the NPM dev
and prod
commands:
watch
command to auto-compile your assets when they are changed: