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

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

koba/filter-builder-eloquent
============================

Extension for the core filter builder library that allows applying filters on eloquent queries.

1.0.1(2mo ago)038↓50%MITPHPPHP ^8.1.0

Since Feb 23Pushed 2mo agoCompare

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

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

Filter Builder for Eloquent
===========================

[](#filter-builder-for-eloquent)

Eloquent adapter for the [filter-builder-core](https://github.com/kobavzw/filter-builder-core) library.

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

[](#installation)

```
composer require koba/filter-builder-eloquent
```

Usage
-----

[](#usage)

### Creating an Eloquent Strategy

[](#creating-an-eloquent-strategy)

```
use App\Models\User;
use Koba\FilterBuilder\Core\Configuration\Configuration;
use Koba\FilterBuilder\Eloquent\EloquentStrategy;

$strategy = new EloquentStrategy(User::class);
$config = new Configuration($strategy);
```

### Filtering Model Attributes

[](#filtering-model-attributes)

Use `makeRule()` to create filters for model attributes:

```
use Koba\FilterBuilder\Core\Enums\ConstraintType;
use Koba\FilterBuilder\Core\Enums\Operation;

$config->addRuleEntry(
    name: 'email',
    type: ConstraintType::STRING,
    supportedOperations: [Operation::EQUALS, Operation::STARTS_WITH],
    boundFilterFn: fn($strategy) => $strategy->makeRule(
        fn($query, $apply) => $apply('email', $query)
    )
);
```

### Filtering Relationships

[](#filtering-relationships)

Use `makeRelation()` to filter based on related models:

```
use App\Models\Post;

// Create configuration for the related model
$postStrategy = new EloquentStrategy(Post::class);
$postConfig = new Configuration($postStrategy);

$postConfig->addRuleEntry(
    name: 'title',
    type: ConstraintType::STRING,
    supportedOperations: [Operation::STARTS_WITH],
    boundFilterFn: fn($strategy) => $strategy->makeRule(
        fn($query, $apply) => $apply('title', $query)
    )
);

// Add relationship filter
$config->addRelationEntry(
    name: 'posts',
    boundFilterFn: fn($strategy) => $strategy->makeRelation(
        Post::class,
        fn($query, $apply) => $query->whereHas('posts', $apply)
    ),
    configuration: $postConfig
);
```

### Applying Filters

[](#applying-filters)

```
$filter = $config->getFilter($filterInput);

$query = User::query();
$filter->apply($query);

$users = $query->get();
```

Examples
--------

[](#examples)

### Using `whereDoesntHave`

[](#using-wheredoesnthave)

```
$config->addRelationEntry(
    name: 'posts',
    boundFilterFn: fn($strategy) => $strategy->makeRelation(
        Post::class,
        fn($query, $apply) => $query->whereDoesntHave('posts', $apply)
    ),
    configuration: $postConfig
);
```

### Filtering on Relationship Attributes

[](#filtering-on-relationship-attributes)

```
$config->addRuleEntry(
    name: 'author_name',
    type: ConstraintType::STRING,
    supportedOperations: [Operation::EQUALS],
    boundFilterFn: fn($strategy) => $strategy->makeRule(
        fn($query, $apply) => $query->whereHas('author', fn($q) => $apply('name', $q))
    )
);
```

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

[](#documentation)

For complete documentation on configuration, filter syntax, operations, and validation, see the [core library](https://github.com/kobavzw/filter-builder-core).

License
-------

[](#license)

MIT

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance83

Actively maintained with recent releases

Popularity11

Limited adoption so far

Community6

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

Every ~0 days

Total

2

Last Release

84d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ccee99f452b602f5b6639aa2d5c94a97de4cb49f0c9656c2f2c8f3dc6418638?d=identicon)[toolbox-kobavzw](/maintainers/toolbox-kobavzw)

---

Top Contributors

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

###  Code Quality

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[algolia/scout-extended

Scout Extended extends Laravel Scout adding algolia-specific features

4186.3M6](/packages/algolia-scout-extended)[swisnl/laravel-fulltext

Fulltext indexing and searching for Laravel

184104.5k6](/packages/swisnl-laravel-fulltext)[kyslik/laravel-filterable

Using URL query strings to filter Eloquent queries.

11539.0k](/packages/kyslik-laravel-filterable)[devnoiseconsulting/laravel-scout-postgres-tsvector

PostgreSQL Full Text Search Driver for Laravel Scout

58110.1k](/packages/devnoiseconsulting-laravel-scout-postgres-tsvector)[vanry/laravel-scout-tntsearch

包含中文分词的 Laravel Scout TNTSearch 驱动，支持 scws, phpanalysis 和 jieba 分词。

17811.8k1](/packages/vanry-laravel-scout-tntsearch)[gtk/larasearch

A driver based solution to searching your Eloquent models supports Laravel 5.2 and Elasticsearch engine.

133.9k](/packages/gtk-larasearch)

PHPackages © 2026

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