PHPackages                             thecodemill/eloquent-filter - 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. thecodemill/eloquent-filter

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

thecodemill/eloquent-filter
===========================

0.5(6y ago)0231MITPHP

Since Feb 8Pushed 6y ago1 watchersCompare

[ Source](https://github.com/thecodemill/eloquent-filter)[ Packagist](https://packagist.org/packages/thecodemill/eloquent-filter)[ RSS](/packages/thecodemill-eloquent-filter/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

EloquentFilter
==============

[](#eloquentfilter)

Add simple filterability to Eloquent models.

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

[](#installation)

Install the EloquentFilter package via Composer:

```
composer require thecodemill/eloquent-filter

```

Usage
-----

[](#usage)

As the name suggests, this package is intended for use with [Eloquent](https://github.com/illuminate/database) and therefor works seamlessly with Laravel.

EloquentFilter allows you to define filter handlers on any of your app's models to make querying much simpler. A filter handler is very similar to a local scope, but by using the `Model::filter()` method, any number of scopes may be applied at once without the need for chaining the individual scopes or query modifiers.

Eg.

```
// With query modifiers
$users = User::where('email', $request->input('email'))
    ->where('age', $request->input('age'))
    ->whereHas('subscription', function ($query) use ($request) {
        $query->where('code', $request->input('subscription'));
    })
    ->get();

// Using EloquentFilter's filter handlers
$users = User::filter($request->all())->get();
```

This is made possible by adding a `filters()` method to the model itself. This method should return a key =&gt; value array of filter names and their respective closures.

```
namespace App;

use TheCodeMill\EloquentFilter\Filterable;

class User
{
    use Filterable;

    /**
     * Return the filter handlers.
     *
     * @return array
     */
    public static function filters()
    {
        return [
            'email' => function ($query, $value) {
                return $query->where('email', $value);
            },
            'age' => function ($query, $value) {
                return $query->where('age', $value);
            },
            'subscription' => function ($query, $value) {
                return $query->whereHas('subscription', function ($query) use ($value) {
                    $query->where('code', $value);
                });
            }
        ];
    }
}
```

If using pagination, EloquentFilter allows you to maintain the query parameters in between page requests. To do so, render the pagination links in your Blade template with the addition of the valid filters that are present in the original page request.

```
// Paginate models in your controller/repository/etc.
$users = User::filter($request->all())->paginate();

// In Blade, append only the valid query parameters:
{{ $users->appends(App\User::validFilters(request()->all()))->links() }}
```

Author
------

[](#author)

- [Andrew Robinson](https://twitter.com/ap_robinson)

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

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 ~196 days

Total

4

Last Release

2423d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/17d681dd2bcd90c88e3f945da141eef4ef3600e19a5973dd62c4cd22fa56688d?d=identicon)[TheCodeMill](/maintainers/TheCodeMill)

### Embed Badge

![Health badge](/badges/thecodemill-eloquent-filter/health.svg)

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

###  Alternatives

[owen-it/laravel-auditing

Audit changes of your Eloquent models in Laravel

3.4k33.0M95](/packages/owen-it-laravel-auditing)[staudenmeir/eloquent-json-relations

Laravel Eloquent relationships with JSON keys

1.1k5.8M24](/packages/staudenmeir-eloquent-json-relations)[bavix/laravel-wallet

It's easy to work with a virtual wallet.

1.3k1.1M11](/packages/bavix-laravel-wallet)[dragon-code/migrate-db

Easy data transfer from one database to another

15717.4k](/packages/dragon-code-migrate-db)[gearbox-solutions/eloquent-filemaker

A package for getting FileMaker records as Eloquent models in Laravel

6454.8k2](/packages/gearbox-solutions-eloquent-filemaker)[cybercog/laravel-ownership

Laravel Ownership simplify management of Eloquent model's owner.

9126.6k3](/packages/cybercog-laravel-ownership)

PHPackages © 2026

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