Download the PHP package touhidurabir/laravel-filterable without Composer
On this page you can find all versions of the php package touhidurabir/laravel-filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download touhidurabir/laravel-filterable
More information about touhidurabir/laravel-filterable
Files in touhidurabir/laravel-filterable
Package laravel-filterable
Short Description A package to filter laravel model based on query params or retrieved model collection
License MIT
Informations about the package laravel-filterable
Laravel Filterable
A package to filter laravel model based on query params or retrived model collection.
Installation
Require/Install the package using composer:
To publish the config file:
Configuration
The package comes with a configuration file named filterable that has to 2 important configs
Base Filter Class
This is a array that contains the base filter class for both the Query and Collection filter as :
If one need to even extend it to add more functionality or any custom feaure, can do it and set the base class in the config file .
Filter Class Namespace
This config define what would be the default namespace(and the store path) of the generated filter classes for the both the Query and Collection filter classes as :
If needed to, one can change the default path from there . but it is also possible to pass a different namespace to the filter generate command to provide a different namespace.
Command
This package includes a handly command to generate filter classes as
It will generate 2 class UserQueryFilter and UserCollectionFilter as per defined namespace in the config file .
This command also includes several handful options to make the filer class generation as flexiable as possible such as
--filters=
By passign comma separated filters, it will put those filters as filterable method in both the query and collection filter class as :
For Query FIlter :
For Collection Filter :
--query-suffix=QueryFilter
Define what would be query filter class file name and class name suffix .
--collection-suffix=CollectionFilter
Define what would be collection filter class file name and class name suffix .
--no-suffix
If passed as switch option or flag, no suffix will be added to query or collection filter class names or files name.
--only-query
If passed as switch option or flag, will only generate the query filters and omit the collection filter class.
--only-collection
If passed as switch option or flag, will only generate the collection filters and omit the query filter class.
--replace
If passed as switch option or flag, will replace the existing file. By defalt if a given file already present, it will not replace it .
Usage
Generate the filters as
it will generate UserQueryFilter.php and UserCollectionFilter.php class at the given path as :
and the use the Filterable trait in the model as
The form some controller, use it as such
Also possible to use an existing array to pass as query to initiate the filter class as
Note that it's not required to pass the $request as if not passed , it will resolve it from the Request Facade . Useful for case like when app running on laravel octane.
It can also handle the filter param validation as :
Set the validation rules there and those params that do not pass the validation will not be applied.
WHY a Collection Filter ?
It is a valid question why a collection filter as most of the time a query filter is sufficient. But some times a collection filter can be helpful to do some custom filter again after records are pull from DB. As this package allow to generate seperate collection filter, in those cases it can be helpful to such cause .
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
License
MIT
All versions of laravel-filterable with dependencies
touhidurabir/laravel-stub-generator Version ^1.0
illuminate/support Version ^8.60
illuminate/console Version ^8.60
illuminate/http Version ^8.60