PHPackages                             samavidev/model-filtration - 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. [Search &amp; Filtering](/categories/search)
4. /
5. samavidev/model-filtration

ActiveLibrary[Search &amp; Filtering](/categories/search)

samavidev/model-filtration
==========================

Filtering the desired model records using query string

1.1.0(3y ago)08MITPHPPHP ^8.1

Since Jan 30Pushed 3y ago1 watchersCompare

[ Source](https://github.com/SamaviDev/model-filtration)[ Packagist](https://packagist.org/packages/samavidev/model-filtration)[ Docs](https://github.com/SamaviDev/model-filtration)[ RSS](/packages/samavidev-model-filtration/feed)WikiDiscussions main Synced yesterday

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

Filtering the desired model records using query string in Laravel app
=====================================================================

[](#filtering-the-desired-model-records-using-query-string-in-laravel-app)

[![Latest Version on Packagist](https://camo.githubusercontent.com/43841f9d896b4820901b1da6399fd94af1311fa3c1372f1787cf6c21e59d9f2f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73616d6176696465762f6d6f64656c2d66696c74726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samavidev/model-filtration)[![GitHub Tests Action Status](https://camo.githubusercontent.com/e3b56fb97a5aae37c0e9157523dd07c0a0c2152e26094ca5a6311ab06396530e/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d6176696465762f6d6f64656c2d66696c74726174696f6e2f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/samavidev/model-filtration/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/e3af0835ea2365eb80541123ac981c37638684a3fa6e327c25e6e1a798136ec3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73616d6176696465762f6d6f64656c2d66696c74726174696f6e2f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/samavidev/model-filtration/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/38e557deb12a3d1780dcb858cb3dbd4d9e15ee3d35611714b95478b2298170db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73616d6176696465762f6d6f64656c2d66696c74726174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/samavidev/model-filtration)

This package provides an annotation to retrieve records of a specific model filtered using a query string. Here's a quick example:

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use SamaviDev\ModelFiltration\Attributes\Filter;

#[Filter(['name' => 'username'])]
class User extends Authenticatable
{
    ...
}
```

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

[](#installation)

You can install the package via composer:

```
composer require samavidev/model-filtration
```

Usage
-----

[](#usage)

- The first argument is valid fields that can be used in the query string. which can be in the form of a string or an array, you can also use an association array to assign a query to a specific model.
- The second argument is the operator that is applied to the table fields (`and`, `or`, `like`, `like:or`). You can even use `with` for relationships. The default value is `and`.

for example:

```
#[Filter(['name' => 'username', 'email' => 'useremail'], 'or')]
```

It can also be used multiple times.

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use SamaviDev\ModelFiltration\Attributes\Filter;

#[Filter('id')]
#[Filter(['name' => 'username'])]
class User extends Authenticatable
{
    ...
}
```

##### Filter group definition:

[](#filter-group-definition)

You can also define an `Attribute` class to use as a group of filters for your models. For this, you must implement the `Group` interface.

```
namespace App\Attributes;

use Attribute;
use SamaviDev\ModelFiltration\Contracts\Group;

#[Attribute]
class UsersFilter implements Group
{
    public function props(): array
    {
        return [
            'or' => ['attribute', ...]
            'and' => ['attribute' => 'alias', ...],
            ...
        ];
    }
}
```

And finally, you can use it in your model like this:

```
namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use App\Attributes\UsersFilter;

#[UsersFilter]
class User extends Authenticatable
{
    ...
}
```

Changelog
---------

[](#changelog)

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

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

[](#contributing)

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

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

[](#security-vulnerabilities)

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

Credits
-------

[](#credits)

- [Mahdi Samavi](https://github.com/SamaviDev)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

1244d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/47baa1241f1fc3975a3ab869c5b716b488c5ea6f085f5963faaeeb3dc3965801?d=identicon)[SamaviDev](/maintainers/SamaviDev)

---

Top Contributors

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

---

Tags

laravellaravel-packagephpphp-attributesphp8laravelSamaviDevmodel-filtration

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/samavidev-model-filtration/health.svg)

```
[![Health](https://phpackages.com/badges/samavidev-model-filtration/health.svg)](https://phpackages.com/packages/samavidev-model-filtration)
```

###  Alternatives

[spatie/laravel-pdf

Create PDFs in Laravel apps

1.0k4.8M47](/packages/spatie-laravel-pdf)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M195](/packages/laravel-ai)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

936603.4k2](/packages/mailerlite-laravel-elasticsearch)[moonshine/moonshine

Laravel administration panel

1.3k253.1k81](/packages/moonshine-moonshine)[spatie/laravel-site-search

A site search engine

309136.6k](/packages/spatie-laravel-site-search)

PHPackages © 2026

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