PHPackages                             buibr/eloquent-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. buibr/eloquent-filter

ActiveLibrary

buibr/eloquent-filter
=====================

Search by filtering query string to eloquent query

v1.3(4mo ago)0390PHPPHP &gt;=7.4|&gt;=8.0

Since Sep 14Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/buibr/eloquent-filter)[ Packagist](https://packagist.org/packages/buibr/eloquent-filter)[ RSS](/packages/buibr-eloquent-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Eloquent Filter
===============

[](#eloquent-filter)

[![Latest Stable Version](https://camo.githubusercontent.com/7f0ce10fa7d239c1a17ba1624e0852ab938aad3547296d67f0224b23463a9def/68747470733a2f2f706f7365722e707567782e6f72672f62756962722f656c6f7175656e742d66696c7465722f762f737461626c65)](https://packagist.org/packages/buibr/eloquent-filter)[![Total Downloads](https://camo.githubusercontent.com/13c09fb3cc6a32693be40e317d13177c24a3b86b8674ceb1cb6ef47b6f2b94a7/68747470733a2f2f706f7365722e707567782e6f72672f62756962722f656c6f7175656e742d66696c7465722f646f776e6c6f616473)](https://packagist.org/packages/buibr/eloquent-filter)[![License](https://camo.githubusercontent.com/e2bd034ffba37a248d354e64db46245c0d8ce28f9bef89cbeacae93e49529a2e/68747470733a2f2f706f7365722e707567782e6f72672f62756962722f656c6f7175656e742d66696c7465722f6c6963656e7365)](https://packagist.org/packages/buibr/eloquent-filter)

`eloquent-filter` is a simple package for filtering Eloquent queries based on request query parameters with predefined methods per parameter. It allows you to easily build complex query filters for your Laravel applications.

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

[](#installation)

You can install the package via composer:

```
composer require buibr/eloquent-filter
```

Usage
-----

[](#usage)

### Step 1: Add `HasFilters` Trait to Your Model

[](#step-1-add-hasfilters-trait-to-your-model)

Include the `HasFilters` trait in any Eloquent model where you want to use query filters.

```
use BI\EloquentFilter\HasFilters;

class YourModel extends Model
{
    use HasFilters;

    // Other model code...
}
```

### Step 2: Create a Filter Class

[](#step-2-create-a-filter-class)

Create a new filter class that extends `QueryFilter`. In this class, define methods for each query parameter you want to filter by. Each method should accept the parameter value and modify the query accordingly.

```
use BI\EloquentFilter\QueryFilter;

class YourModelFilter extends QueryFilter
{
    public function status($value)
    {
        return $this->builder->where('status', $value);
    }

    public function category($value)
    {
        return $this->builder->where('category_id', $value);
    }

    // Add more filter methods as needed...
}
```

### Step 3: Apply the Filter in Your Controller

[](#step-3-apply-the-filter-in-your-controller)

In your controller, apply the filter to the query by using the `filter` scope. Pass an instance of your filter class as the argument.

```
use App\Models\YourModel;
use App\Filters\YourModelFilter;

class YourController extends Controller
{
    public function index(YourModelFilter $filters)
    {
        $items = YourModel::filter($filters)->get();

        return response()->json($items);
    }
}
```

### Example Request

[](#example-request)

You can now filter the query by passing parameters in the request URL:

```
GET /your-models?status=active&category=1

```

This will apply the `status` and `category` filters based on the methods defined in your `YourModelFilter` class.

Customizing Filters
-------------------

[](#customizing-filters)

To customize how filters are applied, simply add more methods to your filter class. Each method corresponds to a query parameter and can modify the Eloquent query as needed.

```
class YourModelFilter extends QueryFilter
{
    public function created_at($value)
    {
        return $this->builder->whereDate('created_at', $value);
    }

    public function sort($value)
    {
        return $this->builder->orderBy('created_at', $value);
    }
}
```

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

[](#contributing)

Contributions are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request.

License
-------

[](#license)

This package is open-sourced software licensed under the [MIT license](LICENSE.md).

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance76

Regular maintenance activity

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Total

4

Last Release

130d ago

PHP version history (2 changes)v1.1PHP &gt;=7.0

v1.2PHP &gt;=7.4|&gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/3f010dfc3a6587d208aa1d9c7bec81d58f21fbf9100b1fce35b5ae05b747d5e5?d=identicon)[buibr](/maintainers/buibr)

---

Top Contributors

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

### Embed Badge

![Health badge](/badges/buibr-eloquent-filter/health.svg)

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11120.2M21](/packages/anourvalar-eloquent-serialize)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)

PHPackages © 2026

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