Require this package with composer.
composer require web-id/flanFLAN uses Laravel Package Auto-Discovery, and doesn't require you to manually add the ServiceProvider.
Copy the package config to your local config with the publish command:
php artisan vendor:publish --provider="WebId\Flan\FlanServiceProvider"Finally, run the filter tables migration
php artisan migrateYou can create a filter with:
php artisan filter:create Useror eventually just the Filter class:
php artisan make:filter:class Useror just the Filter config:
php artisan make:filter:config UserYou can find the configuration files for your Filters in the folder config/FilterConfigs
A configuration file is made of two entries name and filters:
return [
'name' => 'myfilter',
'filters' => [
[
'text' => 'Model ID',
'name' => 'id',
'active' => true,
'field' => [
'type' => 'number',
],
],
// [ ... ]
],
];filters.*.textis the HTML input labelfilters.*.nameis the HTML input name attributefilters.*.activedetermines if the data will be shown in the tablefilters.*.filterabledetermines if the filter input will be shown for this columnfilters.*.fieldcontains options to apply on the inputfilters.*.field.typeis the input type, it can be one of those:checkbox,date,number,select,text
filters.*.field.optionscontains the list of the available select options. Here an example:
'options' => [
[
'value' => '0',
'text' => 'Disabled',
],
[
'value' => '1',
'text' => 'Enabled',
],
// [ ... ],
],Let's say you are defining a BookFilter class, and you want to format the number of pages value:
$this->setDefinition('number_of_pages', [
'custom_select' => 'CONCAT(`number_of_pages`, " pages")',
]);Let's say you are defining a BookFilter class, and you want to be able to filter on the book's author birth city for example.
If you want to use a custom select with a join clause, in your Filter class constructor you can do this:
$this->setDefinition('author_birth_city', [
'join' => 'leftJoinAuthorsTable',
'custom_select' => '`authors`.`birth_city`',
]);Then, you need to add a method named after your join parameter to apply the join on the query, in this example:
protected function leftJoinAuthorsTable(): void
{
$this->query->leftJoin(
'authors',
'books.author_id',
'=',
'authors.id'
);
}The MIT License (MIT). Please see License File for more information.