web-id / flan
FLAN - Filter Like A Ninja
Fund package maintenance!
web-id-fr
Installs: 2 644
Dependents: 0
Suggesters: 0
Security: 0
Stars: 5
Watchers: 9
Forks: 1
Open Issues: 0
Type:project
Requires
- php: ^7.4|^8.0
- friendsofphp/php-cs-fixer: ^3.0
- maatwebsite/excel: ^3.1
Requires (Dev)
- nunomaduro/larastan: ^0.6.13
- orchestra/testbench: ^6.0
- phpstan/phpstan: ^0.12.70
- phpunit/phpunit: ^9.3
- vlucas/phpdotenv: ^5.3
- dev-main
- 0.1.0
- 0.0.1
- dev-update-documentation
- dev-ch5754/tester-le-filtre-de-type-select
- dev-ch2977/modifier-l-organisation-des-inputs-dans-la
- dev-ch2983/bug-typo-dans-le-chemin-de-la-config-generee
- dev-ch2984/commencer-la-documentation-du-package
- dev-leo/fix_only_in_group_by
- dev-leo/fix_validator
- dev-francois/add-routes-service-provider
- dev-leo/starting
This package is auto-updated.
Last update: 2024-10-19 12:21:36 UTC
README
Installation
Require this package with composer.
composer require web-id/flan
FLAN 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 migrate
Usage
You can create a filter with:
php artisan filter:create User
or eventually just the Filter class:
php artisan make:filter:class User
or just the Filter config:
php artisan make:filter:config User
Filter configuration
You 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', ], ], // [ ... ] ], ];
Configuration for any field type:
filters.*.text
is the HTML input labelfilters.*.name
is the HTML input name attributefilters.*.active
determines if the data will be shown in the tablefilters.*.filterable
determines if the filter input will be shown for this columnfilters.*.field
contains options to apply on the inputfilters.*.field.type
is the input type, it can be one of those:checkbox
,date
,number
,select
,text
Configuration specific to select
type:
filters.*.field.options
contains the list of the available select options. Here an example:
'options' => [ [ 'value' => '0', 'text' => 'Disabled', ], [ 'value' => '1', 'text' => 'Enabled', ], // [ ... ], ],
Filter class
The custom_select
definition attribute
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")', ]);
The join
definition attribute
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' ); }
Credits
License
The MIT License (MIT). Please see License File for more information.