PHPackages                             mehdirajabi/filterable - 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. mehdirajabi/filterable

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

mehdirajabi/filterable
======================

Filter eloquent model by array query strings

1.0.0(2y ago)6111MITPHP

Since Jul 26Pushed 2y ago1 watchersCompare

[ Source](https://github.com/mehdirajabi59/filterable-model)[ Packagist](https://packagist.org/packages/mehdirajabi/filterable)[ RSS](/packages/mehdirajabi-filterable/feed)WikiDiscussions main Synced today

READMEChangelog (1)DependenciesVersions (2)Used By (0)

Filter Eloquent Models by Array Query Strings
=============================================

[](#filter-eloquent-models-by-array-query-strings)

Introduction
------------

[](#introduction)

The Laravel Filterable Trait is a powerful package providing a reusable trait for easily implementing filter functionality in your Laravel Eloquent models. It enables filtering query results based on multiple parameters, making it simpler to create dynamic and flexible APIs or data filtering mechanisms in your applications.

Features
--------

[](#features)

- Easily implement filtering on Eloquent models.
- Filter data based on various query parameters.
- Support for multiple filter types, such as exact matches, partial matches, ranges, etc.
- Customizable and extensible for adding new filter types.
- Improves code readability and maintainability by separating filtering logic from the main model.

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

[](#installation)

You can install the package via Composer by running the following command:

```
composer require mehdirajabi/filterable
```

Usage
-----

[](#usage)

1. Apply the Filterable Trait to Your Eloquent Model
----------------------------------------------------

[](#1-apply-the-filterable-trait-to-your-eloquent-model)

Open the Eloquent model where you want to apply the filtering functionality and add the Filterable trait:

```
use Mehdirajabi\Filterable\Filterable;

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

In your controller:

```
class UserController extends Controller
{
    public function index()
    {
        return User::filter()->actived()->get();
    }
}
```

2. How Does Filterable Work?
----------------------------

[](#2-how-does-filterable-work)

Two query strings, filterColumns and filterValues, are used, both being arrays. The default operator for all columns is the "like" operator.

For example:

```
http://test.com/api/user/users?filterColumns[0]=name&filterValues[0]=Alex
```

3. Relational Filter
--------------------

[](#3-relational-filter)

To filter on a relation, add the column name as nested. For example, if a user has a relation with a profile and the profile has a 'sex' column, use the following convention:

```
use Mehdirajabi\Filterable\Filterable;

class User extends Model
{
    use Filterable;

    public function profile()
    {
        return $this->hasOne(UserProfile::class);
    }
}
```

```
http://test.com/api/user/users?filterColumns[0]=profile.sex&filterValues[0]=male
```

4. Change Filter Mode Operator
------------------------------

[](#4-change-filter-mode-operator)

To change the operator of the 'status' column, define the filterMode property:

```
use Mehdirajabi\Filterable\Operators\FilterEqual;

class User extends Model
{
    protected $filterMode = [
        'status' => FilterEqual::class
    ];
}
```

5. Change Operator in Controller
--------------------------------

[](#5-change-operator-in-controller)

```
use Mehdirajabi\Filterable\Operators\FilterBetween;

class UserController extends Controller
{
    public function index()
    {
        return User::filter(['id' => FilterBetween::class])->paginate(100);
    }
}
```

Between Operator
----------------

[](#between-operator)

```
use Mehdirajabi\Filterable\Operators\FilterBetween;

class User extends Model
{
    protected $filterMode = [
        'created_at' => FilterBetween::class
    ];
}
```

```
http://test.com/users?filterColumns[0]=created_at&filterValues[0]=2023-06-23 00:00:00, 2023-06-24 23:59:59
```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

1073d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7848036?v=4)[Mehdi Rajabi](/maintainers/mehdirajabi59)[@mehdirajabi59](https://github.com/mehdirajabi59)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/mehdirajabi-filterable/health.svg)

```
[![Health](https://phpackages.com/badges/mehdirajabi-filterable/health.svg)](https://phpackages.com/packages/mehdirajabi-filterable)
```

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[pgvector/pgvector

pgvector support for PHP

198741.5k12](/packages/pgvector-pgvector)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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