PHPackages                             atldays/laravel-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. atldays/laravel-eloquent-filters

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

atldays/laravel-eloquent-filters
================================

Advanced Laravel models filtering capabilities

v2.1.0(1mo ago)0451MITPHPPHP ^8.1CI passing

Since Apr 10Pushed 1mo agoCompare

[ Source](https://github.com/atldays/laravel-eloquent-filters)[ Packagist](https://packagist.org/packages/atldays/laravel-eloquent-filters)[ Docs](https://github.com/atldays/laravel-eloquent-filters)[ GitHub Sponsors](https://github.com/atldays)[ RSS](/packages/atldays-laravel-eloquent-filters/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (3)Dependencies (6)Versions (5)Used By (1)

Advanced Laravel models filtering capabilities
==============================================

[](#advanced-laravel-models-filtering-capabilities)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4d22f95c5a8b73dfcab37ebfbc1a79d430a289bb839004bc5122a9ea2c14132b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61746c646179732f6c61726176656c2d656c6f7175656e742d66696c746572732e7376673f6c6f676f3d7061636b6167697374267374796c653d666f722d7468652d6261646765)](https://packagist.org/packages/atldays/laravel-eloquent-filters)[![Total Downloads](https://camo.githubusercontent.com/393669523442f198dca58007fe08956185a9f67ffd22bb0d0680ae0d0a59bb2c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61746c646179732f6c61726176656c2d656c6f7175656e742d66696c746572732e7376673f7374796c653d666f722d7468652d626164676526636f6c6f723d626c7565)](https://packagist.org/packages/atldays/laravel-eloquent-filters)[![CI](https://camo.githubusercontent.com/f21a14d25bad0c8397a4cb6b05144a593466f5851f10628bd7086c6604ed6a37/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61746c646179732f6c61726176656c2d656c6f7175656e742d66696c746572732f63692e79616d6c3f7374796c653d666f722d7468652d6261646765266c6162656c3d4349)](https://github.com/atldays/laravel-eloquent-filters/actions/workflows/ci.yaml)[![License: MIT](https://camo.githubusercontent.com/7a1226d14a365d288bfe51ece915ee0c7e754a16faa51ff06436504de29b33b4/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e7376673f7374796c653d666f722d7468652d6261646765)](LICENSE.md)

This package is maintained by Atldays and is based on a fork of the original [`pricecurrent/laravel-eloquent-filters`](https://github.com/pricecurrent/laravel-eloquent-filters)package.

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

[](#installation)

You can install the package via composer:

```
composer require atldays/laravel-eloquent-filters
```

Compatibility
-------------

[](#compatibility)

The package currently supports Laravel 10, 11, 12, and 13.

Usage
-----

[](#usage)

This package gives you fine-grained control over how you may go about filtering your Eloquent Models.

This package is particularly good when you need to address complex use-cases, implementing filtering on many parameters, using complex logic.

But let's start with simple example:

Consider you have a Product, and you need to filter products by `name`:

```
use App\Filters\NameFilter;
use Atldays\EloquentFilters\EloquentFilters;

class ProductsController
{
    public function index(Request $request)
    {
        $filters = EloquentFilters::make([new NameFilter($request->name)]);

        $products = Product::filter($filters)->get();
    }
}
```

Generate eloquent-filter

```
php artisan make:eloquent-filter NameFilter
```

This will put your Filter to the app/Filters directory by default. You may prefix the name with the path, like `Models/Product/NameFilter`.

```
php artisan make:eloquent-filter Models/Product/NameFilter
```

You can use the `--field=name` argument to generate your filter with the field name

```
php artisan make:eloquent-filter Models/Product/NameFilter --field=name
```

Here is what your `NameFilter` might look like:

```
use Atldays\EloquentFilters\AbstractEloquentFilter;
use Illuminate\Database\Eloquent\Builder;

class NameFilter extends AbstractEloquentFilter
{
    protected $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function apply(Builder $query): Builder
    {
        return $query->where('name', 'like', "{$this->name}%");
    }
}
```

Notice how our Filter has no clue it is tied up with a specific Eloquent Model? That means, we can simply re-use it for any other model, where we need to bring in the same name filtering functionality:

```
use App\Filters\NameFilter;
use App\Models\User;
use Atldays\EloquentFilters\EloquentFilters;

class UsersController
{
    public function index(Request $request)
    {
        $filters = EloquentFilters::make([new NameFilter($request->user_name)]);

        $products = User::filter($filters)->get();
    }
}
```

You can chain methods from the filter as if it was simply an Eloquent Builder method:

```
use App\Filters\NameFilter;
use App\Models\User;
use Atldays\EloquentFilters\EloquentFilters;

class UsersController
{
    public function index(Request $request)
    {
        $filters = EloquentFilters::make([new NameFilter($request->user_name)]);

        $products = User::query()
            ->filter($filters)
            ->limit(10)
            ->latest()
            ->get();
    }
}
```

To enable filtering capabilities on an Eloquent Model simply import the trait `Filterable`

```
use Atldays\EloquentFilters\Filterable;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    use Filterable;
}
```

You may also pass a single filter or an array of filters directly:

```
Product::filter(new NameFilter($request->name))->get();

Product::filter([
    new NameFilter($request->name),
    new IsActiveFilter($request->boolean('active')),
])->get();
```

### More complex use-case

[](#more-complex-use-case)

This approach scales very well when you are dealing with a real-life larger applications where querying data from the DB goes far beyond simple comparison by a name field.

Consider an app where we have Stores with a Location coordinates and we have products in stock and we need to query all products that are in stock in a store that is in 10 miles radius

We may stuff all the logic in the controller with some pseudo-code:

```
class ProductsController
{
    public function index(Request $request)
    {
        $products Product::query()
            ->when($request->in_stock, function ($query) {
                $query->join('product_stock', fn ($q) => $q->on('product_stock.product_id', '=', 'products.id')->where('product_stock.quantity', '>', 0));
            })
            ->when($request->within_radius, function ($query) {
                $coordinates = auth()->user()->getCoordinates();
                $query->join('stores', 'stores.id', '=', 'product_stock.store_id');
                $query->whereRaw('
                    ST_Distance_Sphere(
                        Point(stores.longitude, stores.latitude),
                        Point(?, ?)
                    ) get();

        return response()->json(['data' => $products]);
    }
}
```

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review our [security policy](.github/SECURITY.md) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Anjey Tsibylskij](https://github.com/atldays)
- Forked from [pricecurrent/laravel-eloquent-filters](https://github.com/pricecurrent/laravel-eloquent-filters)

License
-------

[](#license)

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

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance89

Actively maintained with recent releases

Popularity8

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity45

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 56.1% 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 ~1 days

Total

3

Last Release

57d ago

Major Versions

v1.0.0 → v2.0.02026-04-11

### Community

Maintainers

![](https://www.gravatar.com/avatar/d3d0138ffb1733c52bcd1602597088817ed576f8f9489a3b58095cf5c84264ca?d=identicon)[atldays](/maintainers/atldays)

---

Top Contributors

[![pricecurrent](https://avatars.githubusercontent.com/u/4919983?v=4)](https://github.com/pricecurrent "pricecurrent (37 commits)")[![atldays](https://avatars.githubusercontent.com/u/130153594?v=4)](https://github.com/atldays "atldays (23 commits)")[![medeiroz](https://avatars.githubusercontent.com/u/11270546?v=4)](https://github.com/medeiroz "medeiroz (2 commits)")[![rkrater](https://avatars.githubusercontent.com/u/1753094?v=4)](https://github.com/rkrater "rkrater (2 commits)")[![SupianIDz](https://avatars.githubusercontent.com/u/37969970?v=4)](https://github.com/SupianIDz "SupianIDz (1 commits)")[![tom-knight](https://avatars.githubusercontent.com/u/1437113?v=4)](https://github.com/tom-knight "tom-knight (1 commits)")

---

Tags

eloquentfilterslaravelphpquery-builderlaraveleloquent-filterslaravel-eloquent-filtersmodel-filtersatldays

###  Code Quality

Code StyleLaravel Pint

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-medialibrary

Associate files with Eloquent models

6.1k41.3M594](/packages/spatie-laravel-medialibrary)[kirschbaum-development/eloquent-power-joins

The Laravel magic applied to joins.

1.6k29.9M42](/packages/kirschbaum-development-eloquent-power-joins)[spatie/laravel-health

Monitor the health of a Laravel application

88011.3M149](/packages/spatie-laravel-health)[psalm/plugin-laravel

Psalm plugin for Laravel

3325.1M337](/packages/psalm-plugin-laravel)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8733.1M23](/packages/yajra-laravel-oci8)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

436834.4k1](/packages/clickbar-laravel-magellan)

PHPackages © 2026

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