Download the PHP package duuany/eloquent-filters without Composer
On this page you can find all versions of the php package duuany/eloquent-filters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download duuany/eloquent-filters
More information about duuany/eloquent-filters
Files in duuany/eloquent-filters
Package eloquent-filters
Short Description A simplest Eloquent query filter package.
License MIT
Informations about the package eloquent-filters
Eloquent Filters
A simplest Eloquent Model URL query filter package for your Laravel
Instalation
You can install via composer:
Laravel 5.5+
Laravel 5.4 or above
Add the service provider to your config/app.php
``
Optionally, you can publish config file to override package configuration
Usage
In your model, add the following HasFilters trait
Create a UserFilter class anywhere in your app folder. Filter classes defines array of applicable filters. For each filter added to array of filters, you need to implement the filter logic.
You can create filters via artisan command
You can pass multiple parameters to your filters, like this:
When passing more than one paramenter to filter, make sure use a delimiter in your query string.
The default delimiter its :
, but your can modify overriding the protected $delimiter
property.
Example:
In query string...
... keep in mind, to not use special query strings characters like delimiters.
Magic Calls
Optionally, you can ommit ->builder
:
Now in your application you can use the filters as the following:
When the user access the URL http://localhost/?order=id, the order filter will be applied on the User model.
Testing
Credits
- Jeffrey Way
- Jorge Junior aka jjquady
- Many coffee cups :D
License
The MIT License (MIT). Please see License File for more information.