PHPackages                             gurgentil/eloquent-filters - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. gurgentil/eloquent-filters

ActiveLibrary[Database &amp; ORM](/categories/database)

gurgentil/eloquent-filters
==========================

A Laravel package to add query filters to your Eloquent models with ease

1.0.1(5y ago)15225MITPHPPHP ^7.2

Since Dec 7Pushed 5y ago1 watchersCompare

[ Source](https://github.com/gurgentil/eloquent-filters)[ Packagist](https://packagist.org/packages/gurgentil/eloquent-filters)[ Docs](https://github.com/gurgentil/eloquent-sequencer)[ RSS](/packages/gurgentil-eloquent-filters/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (2)Dependencies (2)Versions (4)Used By (0)

Eloquent Filters
================

[](#eloquent-filters)

[![Latest Version](https://camo.githubusercontent.com/1dca13704d9bdfcc3227b87511a33bcc216be0779f2078b4eb002e67473ead45/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f67757267656e74696c2f656c6f7175656e742d66696c746572732e7376673f7374796c653d666c61742d737175617265)](https://github.com/gurgentil/eloquent-filters/releases)[![GitHub Workflow Status](https://camo.githubusercontent.com/0aa05a60bbba3556e4890d19d5375da4dff6b37fbf72e55f0c41efe852648b3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f67757267656e74696c2f656c6f7175656e742d66696c746572732f72756e2d74657374733f6c6162656c3d7465737473)](https://camo.githubusercontent.com/0aa05a60bbba3556e4890d19d5375da4dff6b37fbf72e55f0c41efe852648b3f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f67757267656e74696c2f656c6f7175656e742d66696c746572732f72756e2d74657374733f6c6162656c3d7465737473)[![Quality Score](https://camo.githubusercontent.com/7a661d3119b4d166fbaff3e72086b9df3b4574d39615b108c4d06987830f737c/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f67757267656e74696c2f656c6f7175656e742d66696c746572732e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/gurgentil/eloquent-filters)[![MIT Licensed](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

This package provides a nice and easy way to add query filters to your Eloquent models without turning your model classes into massive God objects.

After setting it up, if you are building an API, for example, you can simply add this piece of code to your controller:

```
User::filter($request->get('filter'))->get();
```

Now make a request to `/api/users?filter[name]=John` and let the fun begin.

Installation
------------

[](#installation)

Install the package via composer:

```
composer require gurgentil/eloquent-filters
```

Usage
-----

[](#usage)

Create a filter builder that extends `Gurgentil\EloquentFilters\FilterBuilder`. This is where you will register all the filters for your Eloquent model.

```
namespace App\Filters;

use Gurgentil\EloquentFilters\FilterBuilder;

class UserFilters extends FilterBuilder
{
    protected $availableFilters = [];
}
```

Add the `Gurgentil\EloquentFilters\Filterable` trait to your model class. The trait will look for a filter builder for the model inside `App\Filters`.

Creating filters
----------------

[](#creating-filters)

Run the artisan command:

```
php artisan make:filter Users/NameFilter
```

Register the filter in the builder you created previously:

```
namespace App\Filters;

use App\Filters\Users\NameFilter;
use Gurgentil\EloquentFilters\FilterBuilder;

class UserFilters extends FilterBuilder
{
    protected $availableFilters = [
        'name' => NameFilter::class,
    ];
}
```

Last but not least, implement your query in `NameFilter`:

```
namespace App\Filters\Users;

use Gurgentil\EloquentFilters\Filter;
use Illuminate\Database\Eloquent\Builder;

class NameFilter implements Filter
{
    /**
     * Apply filter.
     *
     * @return Builder
     */
    public function apply(Builder $builder, $value)
    {
        return $builder->where('name', $value);
    }
}
```

You can perform filter queries on your model by passing a list of filters to the `filter` method:

```
User::filter([
    'name' => 'John',
])->get();
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Credits
-------

[](#credits)

- [Gustavo Rorato Gentil](https://github.com/gurgentil)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~39 days

Total

2

Last Release

1943d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6fe26ccdc056dd1ae4c15a44e7799340501cc7a7e58d138b1fcb78b0034693e1?d=identicon)[gurgentil](/maintainers/gurgentil)

---

Top Contributors

[![gurgentil](https://avatars.githubusercontent.com/u/12678835?v=4)](https://github.com/gurgentil "gurgentil (43 commits)")

---

Tags

eloquentfilterslaravellaraveleloquentqueryfilters

### Embed Badge

![Health badge](/badges/gurgentil-eloquent-filters/health.svg)

```
[![Health](https://phpackages.com/badges/gurgentil-eloquent-filters/health.svg)](https://phpackages.com/packages/gurgentil-eloquent-filters)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[reedware/laravel-relation-joins

Adds the ability to join on a relationship by name.

2121.2M13](/packages/reedware-laravel-relation-joins)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[cerbero/query-filters

Filter Laravel Eloquent models based on query parameters.

85282.6k](/packages/cerbero-query-filters)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)[czim/laravel-filter

Filter for Laravel Eloquent queries, with support for modular filter building

8973.0k3](/packages/czim-laravel-filter)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
