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

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

leocarmo/laravel-eloquent-model-filter
======================================

Filter your Eloquent Model easier

1.0.0(7y ago)11842MITPHPPHP &gt;=7

Since Aug 21Pushed 7y ago1 watchersCompare

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

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

Laravel Eloquent model filter
=============================

[](#laravel-eloquent-model-filter)

[![Code Quality](https://camo.githubusercontent.com/fda2bbc91548254914176badb9ccfe477a3d2431bac9a4e0d928f37925be116e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656f6361726d6f2f6c61726176656c2d656c6f7175656e742d6d6f64656c2d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/leocarmo/php-telegram-bot/?branch=master)[![Build Status](https://camo.githubusercontent.com/720d373e3d6930faccad51bfcf60f22e0aa9eb9110319adfcc583ec32320b2bf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656f6361726d6f2f6c61726176656c2d656c6f7175656e742d6d6f64656c2d66696c7465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/leocarmo/php-telegram-bot/build-status/master)[![Code Intelligence Status](https://camo.githubusercontent.com/1b334d935dc349e921c7c1112ef3d351e219cc0c24f0c2231e9fa2b255b121f9/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6c656f6361726d6f2f6c61726176656c2d656c6f7175656e742d6d6f64656c2d66696c7465722f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d6173746572)](https://scrutinizer-ci.com/code-intelligence)[![Total Downloads](https://camo.githubusercontent.com/cf34e0f323a0472f92f3771e86df2002b735e2a632115c3ca19ce011f801ef78/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c656f6361726d6f2f6c61726176656c2d656c6f7175656e742d6d6f64656c2d66696c7465722e737667)](https://packagist.org/packages/leocarmo/laravel-eloquent-model-filter)

Now you can filter your model dynamically. This is not a powerful search system, but this can help you with small projects when you need more time in others features and simple filters.

```
composer require leocarmo/laravel-eloquent-model-filter

```

Usage
-----

[](#usage)

First, implement the `Trait` on your model, like this:

```
use LeoCarmo\ModelFilter\Traits\FilterableModel;
use Illuminate\Database\Eloquent\Model;

class YourModel extends Model
{

    use FilterableModel;

}
```

Now you can use all available methods, we will pass thought later. But after this, some required attributes are required to use all features from this filter.

---

First attribute is `filterable`, with these you can set all allowed filters and the operator for this attribute. Like this:

```
class YourModel extends Model
{

    use FilterableModel;

    protected $filterable = [
        'id',
        'name' => 'LIKE',
        'email',
        'age' => '>=',
        'phone'
    ];

}
```

The second is `filterable_select`, with these you set columns to select on query. This is very important for fast queries. If this attribute is not present on model, all columns will be returned (`*` operator).

```
class YourModel extends Model
{

    use FilterableModel;

    protected $filterable_select = [
        'id', 'name', 'email', 'age'
    ];

}
```

Now, all required configurations are set. You can start all your filters like this:

```
class YourController
{

    public function filter(Request $request)
    {
        return (new YourModel)->filter($request->all())->get();
    }

}
```

*Important: This Trait return Illuminate\\Database\\Query\\Builder instance, so you can use all available methods like `paginate()` and `orderBy()` to power up your filter*

Tips
====

[](#tips)

The default operator is `=`, so, for all queries this will be used. You can change this with `changeDefaultOperator()` method.

---

When you use `LIKE` operator, the search will be: `%SEARCH%`

Available methods
=================

[](#available-methods)

To assume all the control, you can change model default filter configuration in a specific request.

#### pushFilterableSelect()

[](#pushfilterableselect)

This method will push new columns to the select query.

---

Example: on your model you defined `id` and `name`, but in a specific request you want to show the `age`, you can use this method.

```
$model->pushFilterableSelect('age');
// OR
$model->pushFilterableSelect(['age', 'created_at']);
```

#### pushFilterable()

[](#pushfilterable)

With this, you can push new columns to allowed filter or change the operator for an existent column.

---

If you push a column that was defined on model with the attribute `filterable` and an operator, the original value will be override with the new operator.

```
// this first example will not overide the original column if the default value has an operator seted, but will push to the allowed filters if was not defined
$model->pushFilterable('age');

// this example will overide the original operator
$model->pushFilterable(['age' => '>']);
```

#### changeDefaultOperator()

[](#changedefaultoperator)

The default operator is `=` when no operator was defined on model. If you want, you can change this:

```
$model->changeDefaultOperator('LIKE');
```

Credits
=======

[](#credits)

- [Leonardo Carmo](https://github.com/leocarmo)

###  Health Score

30

—

LowBetter than 62% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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

2871d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/21243754?v=4)[Leonardo Carmo](/maintainers/leocarmo)[@leocarmo](https://github.com/leocarmo)

---

Top Contributors

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

---

Tags

eloquenteloquent-filterseloquent-modelsfilterlaravellaravel-packagephpphp7

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

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

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

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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