PHPackages                             lacodix/laravel-model-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. lacodix/laravel-model-filter

ActiveLaravel-package[Database &amp; ORM](/categories/database)

lacodix/laravel-model-filter
============================

A Laravel package to filter, search and sort models with ease while fetching from database.

v4.3.0(1mo ago)17649.9k—1.7%14[1 issues](https://github.com/lacodix/laravel-model-filter/issues)MITPHPPHP ^8.2CI passing

Since Jan 17Pushed 1mo ago3 watchersCompare

[ Source](https://github.com/lacodix/laravel-model-filter)[ Packagist](https://packagist.org/packages/lacodix/laravel-model-filter)[ Docs](https://github.com/lacodix/laravel-model-filter)[ GitHub Sponsors](https://github.com/lacodix)[ RSS](/packages/lacodix-laravel-model-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (38)Versions (111)Used By (0)

laravel-model-filter
====================

[](#laravel-model-filter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/999cf03690fd97fd4d1c968ae92fb12ee70be238d9102ed709d0c722024fa470/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61636f6469782f6c61726176656c2d6d6f64656c2d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lacodix/laravel-model-filter)[![GitHub Tests Action Status](https://camo.githubusercontent.com/7abcfeb50b9b6edf2f32cfc2076547fb09a47ed305d56d78abbf0afcb11d732a/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c61636f6469782f6c61726176656c2d6d6f64656c2d66696c7465722f746573742e79616d6c3f6272616e63683d6d6173746572266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/lacodix/laravel-model-filter/actions?query=workflow%3Atest+branch%3Amaster)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/203488a8e08be8def758114bb1f6527cff37f11097a02c34d0c1419a0b13ec9d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6c61636f6469782f6c61726176656c2d6d6f64656c2d66696c7465722f7374796c652e79616d6c3f6272616e63683d6d6173746572266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/lacodix/laravel-model-filter/actions?query=workflow%3Astyle+branch%3Amaster)[![Total Downloads](https://camo.githubusercontent.com/b06de407d6f4ea4f50161a149841869382df352fdfde18378ca213b55386e057/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61636f6469782f6c61726176656c2d6d6f64656c2d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/lacodix/laravel-model-filter)

This package allows you to filter, search and sort models while fetching from database with ease. It contains additional functionality to use query strings to filter, search and sort.

With this package you can easily filter, search and sort your Eloquent models. It supports various filter types like strings, dates, numbers, and enums out of the box. You can also create complex custom filters to handle any specific database logic.

Additionally you can use the visualisation functionality of filters.

Documentation
-------------

[](#documentation)

You can find the entire documentation for this package on [our documentation site](https://www.lacodix.de/docs/laravel-model-filter)

See our [Upgrade Guide](docs/upgrade.md) for information on how to upgrade from older versions.

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

[](#installation)

```
composer require lacodix/laravel-model-filter
```

Basic Usage
-----------

[](#basic-usage)

### Filter

[](#filter)

Create your first filter

```
php artisan make:filter CreatedAfterFilter --type=date --field=created_at
```

Filters can be applied directly to models, but they can also be easily applied to relations and nested relations using the `RunsOnRelation` trait. This automatically wraps the filter logic in a `whereHas` closure and correctly qualifies the field names using the related table.

```
// Set the filter mode
// App\Models\Filters\CreatedAfterFilter
public FilterMode $mode = FilterMode::GREATER_OR_EQUAL;

// Apply this filter and the HasFilters trait to a Model
// App\Models\Post
use HasFilters;
protected array $filters = [
    CreatedAfterFilter::class,
];

// Somwhere in a controller, select all posts created after 1st of January 2023
Post::filter(['created_after_filter' => '2023-01-01'])->get();

// Do the same via query string by calling
// this url: https://.../posts?created_after_filter=2023-01-01
Post::filterByQueryString()->get();
```

### Search

[](#search)

```
// add searchable fields and the IsSearchable trait to Model:
// App\Models\Post
use IsSearchable;
protected array $searchable = [
    'title',
    'content',
];

// Somewhere in controller, find all posts that contain "test" in title or content
Post::search('test')->get();

// Do the same via query string by calling
// this url: https://.../posts?search=test
Post::searchByQueryString()->get();
```

### Visualize

[](#visualize)

All filters have a blade template that can visualize the filter with one or multiple input fields. To visualize all filters of a dedicated model you can use a blade component:

```

```

### Grouping

[](#grouping)

Sometimes you don't need all of the filters for all parts of a web application. Maybe there shall be different filters be available to the backend as in the frontend, or different user types shall be able to use different filters.

For such cases this package offers filter grouping when adding filters to models

```
protected array $filters = [
    'frontend' => [
        HotFilter::class,
    ],
    'backend' => [
        CreatedAfterFilter::class,
        PublishedFilter::class,
    ]
];
```

The groups can be used in the scopes

```
Post::filterByQueryString('frontend')->get()
```

or

```
Post::filter(['hot_filter' => 'hot'], 'frontend')->get();
Post::filter(['created_after_filter' => '2023-01-01'], 'backend')->get();
```

Testing
-------

[](#testing)

```
composer test
```

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

[](#contributing)

Please run the following commands and solve potential problems before committing and think about adding tests for new functionality.

```
composer rector:test
composer insights
composer csfixer:test
composer phpstan:test
```

Changelog
---------

[](#changelog)

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

Credits
-------

[](#credits)

- [lacodix](https://github.com/lacodix)

License
-------

[](#license)

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

###  Health Score

61

—

FairBetter than 99% of packages

Maintenance89

Actively maintained with recent releases

Popularity47

Moderate usage in the ecosystem

Community17

Small or concentrated contributor base

Maturity75

Established project with proven stability

 Bus Factor1

Top contributor holds 98.4% 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 ~13 days

Recently: every ~1 days

Total

88

Last Release

57d ago

Major Versions

v1.11.3 → v2.0.02024-03-12

v1.x-dev → v2.1.02024-03-24

v2.3.2 → v3.0.02024-06-17

v2.x-dev → v3.0.12024-06-20

v3.x-dev → v4.0.02026-03-16

PHP version history (2 changes)v0.1.0PHP ^8.1

v4.2.0PHP ^8.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/123ffce0596acef2904868164413bca95eeeaa4e2ba557b3620f11fce22cfbb7?d=identicon)[lacodix](/maintainers/lacodix)

---

Top Contributors

[![renky](https://avatars.githubusercontent.com/u/6528960?v=4)](https://github.com/renky "renky (186 commits)")[![bearcodi](https://avatars.githubusercontent.com/u/210376?v=4)](https://github.com/bearcodi "bearcodi (1 commits)")[![khanalpride](https://avatars.githubusercontent.com/u/6267947?v=4)](https://github.com/khanalpride "khanalpride (1 commits)")[![renitreni](https://avatars.githubusercontent.com/u/17608701?v=4)](https://github.com/renitreni "renitreni (1 commits)")

---

Tags

eloquentfilterlaravellaravel-packagemodelsearchlaravelmodeleloquentfilterfilterslacodix

###  Code Quality

TestsPest

Static AnalysisPHPStan, Rector

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/lacodix-laravel-model-filter/health.svg)

```
[![Health](https://phpackages.com/badges/lacodix-laravel-model-filter/health.svg)](https://phpackages.com/packages/lacodix-laravel-model-filter)
```

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[jedrzej/searchable

Searchable trait for Laravel's Eloquent models - filter your models using request parameters

127259.1k5](/packages/jedrzej-searchable)[jedrzej/pimpable

Laravel 4/5/6 package that allows to dynamically filter, sort and eager load relations for your models using request parameters

105179.0k1](/packages/jedrzej-pimpable)[indexzer0/eloquent-filtering

Powerful eloquent filtering

22425.9k3](/packages/indexzer0-eloquent-filtering)[aldemeery/sieve

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

1396.3k](/packages/aldemeery-sieve)

PHPackages © 2026

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