LaravelPackages.net
Acme Inc.
Toggle sidebar
atnic/eloquent-filters

Laravel 5 Filterable Eloquents.

1.030
0
2.2.2
About atnic/eloquent-filters

atnic/eloquent-filters is a Laravel package for laravel 5 filterable eloquents.. It currently has 0 GitHub stars and 1.030 downloads on Packagist (latest version 2.2.2). Install it with composer require atnic/eloquent-filters. Discover more Laravel packages by atnic or browse all Laravel packages to compare alternatives.

Last updated

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 [email protected] instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

Star History Chart