atnic/eloquent-filters
| Install | |
|---|---|
composer require atnic/eloquent-filters |
|
| Latest Version: | 2.2.2 |
| PHP: | ^7.3|^8.0 |
| Laravel: | 6 · 7 · 8 |
| Older releases: | 5 |
| License: | MIT |
| Last Updated: | Dec 6, 2021 |
| Links: | GitHub · Packagist |
Filterable Eloquent
Easily filter Laravel Eloquent queries by using URL query strings.
Installation
Install the package via composer
composer require atnic/eloquent-filters
Usage
First you need to add Filterable trait and filters attribute to your model as the following:
use Smartisan\Filters\Traits\Filterable;
class User extends Model
{
use Filterable;
protected $filters = App\Filters\UserFilter::class;
}
Then create UserFilter class and define your filters as public methods:
use Smartisan\Filters\Filter;
class UserFilter extends Filter
{
public function status($code)
{
return $this->builder->where('status', $code);
}
}
Note that you are able to access the query builder instance of user by using $this->builder.
Now in order to check for URL query strings and perform the corrosponding filter, you need to use User::filter($request)->get().
Security
If you discover any security related issues, please email mohd.itcs@gmail.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.
Related Packages
Powerful PHP database abstraction layer (DBAL) with many features for database s...
Version History
| Version | Released | PHP | Laravel | License |
|---|---|---|---|---|
| 2.2.2 | ^7.3| | ^6.20.26| | MIT | |
| 2.2.1 | ^7.0 | ^5.5 | MIT |