PHPackages                             henzeb/query-filter-builder - 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. henzeb/query-filter-builder

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

henzeb/query-filter-builder
===========================

A fancy way to build filters

v1.3.0(2y ago)243AGPL-3.0-onlyPHPPHP ^8.1

Since Feb 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/henzeb/query-filter-builder)[ Packagist](https://packagist.org/packages/henzeb/query-filter-builder)[ Docs](https://github.com/henzeb/query-filter-builder)[ RSS](/packages/henzeb-query-filter-builder/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (8)Dependencies (4)Versions (9)Used By (0)

Query Filter Builder
====================

[](#query-filter-builder)

[![Build Status](https://github.com/henzeb/query-filter-builder/workflows/tests/badge.svg)](https://github.com/henzeb/query-filter-builder/actions)[![Latest Version on Packagist](https://camo.githubusercontent.com/15637fb092395c006840626b8e91bede9bc1c2b08169c8fb30be2635c5fc6440/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f68656e7a65622f71756572792d66696c7465722d6275696c6465722e737667)](https://packagist.org/packages/henzeb/query-filter-builder)[![Total Downloads](https://camo.githubusercontent.com/7877409980cb686d98e14d71e53430b87a4c0cedd4455ff9e69e2b6b69d5dcee/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f68656e7a65622f71756572792d66696c7465722d6275696c6465722e737667)](https://packagist.org/packages/henzeb/query-filter-builder)[![Test Coverage](https://camo.githubusercontent.com/9b07cd0ae44058a0f80fa4b31354a878c0814cde073a1860abd7a0a6338e2b43/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f30333333353830336633336431326263343562642f746573745f636f766572616765)](https://codeclimate.com/github/henzeb/query-filter-builder/test_coverage)

Whenever you need filters on your API's endpoints, this package gives you a nice and simple interface that allows you to add filters without the need of a thousand parameters passed to your methods or writing SQL queries inside your controllers.

This comes with support for Laravel. If you'd like to contribute for other frameworks, see [Contributing](CONTRIBUTING.md).

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

[](#installation)

You can install the package via composer:

```
composer require henzeb/query-filter-builder
```

Usage
-----

[](#usage)

See [here](doc/LARAVEL.md) for Laravel specific usage.

In your controller you may build up something like this, based on parameters given by the user of your application.

```
use Henzeb\Query\Filters\Query;

$filter = (new Query())
    ->nest(
        (new Query)
            ->nest(
                (new Query)
                    ->is('animal', 'cat')
                    ->less('age', 10)
            )->or()
            ->nest(
                (new Query)
                    ->is('animal', 'dog')
                    ->between('age', 5, 7)
            )
    )->in('disease', 'diabetes', 'diarrhea')
    ->limit(50)
    ->offset(50);
```

Building the query using Laravel's query builder, can be done as such:

```
use DB;
use Henzeb\Query\Illuminate\Builders\Builder;

$query = DB::table('patients')
    ->where('vet_id', 1);

$filter->build(new Builder($query));
```

This would result in the following query:

```
select *
from `patients`
where `vet_id` = ?
  and (
          (`animal` = ? and `age` whereRaw(
            '(
                select count(1)
                from `owners_patients`
                where `owners_patients`.`patient_id` = `patients`.`id`
            ) = ?',
            [$this->count]
        );
    }
}
```

You can then call it like this:

```
use Henzeb\Query\Filters\Query;
use App\Filters\YourCustomFilter;

$filter = (new Query)->filter(OwnerCountFilter(1));
```

Which would result in a query like this:

```
select *
from `patients`
where `vet_id` = ?
  and (
            (
                select count(1)
                from `owners_patients`
                where `owners_patients`.`patient_id` = `patients`.`id`
            ) = ?
      )
```

Creating your own builder.
--------------------------

[](#creating-your-own-builder)

Simply implement the `Henzeb\Query\Builders\Contracts\QueryBuilder` interface.

### Custom filters

[](#custom-filters-1)

The custom filters approach might feel a bit strange. You must create your own custom filter interface, as the default `Henzeb\Query\Illuminate\Filters\Contracts\Filter` interface does not have any methods.

See `Henzeb\Query\Illuminate\Builders\Builder` for an example on proxying in order to enable your IDE's typehinting.

If you have a better approach, please let me know or submit a pull-request.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

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

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Henze Berkheij](https://github.com/henzeb)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity11

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity63

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

Every ~106 days

Recently: every ~185 days

Total

8

Last Release

797d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.3.0PHP ^8.1

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/15928532?v=4)[henzeb](/maintainers/henzeb)[@henzeb](https://github.com/henzeb)

---

Top Contributors

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

---

Tags

laravelquerybuilderfilterhenzebagnostic

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/henzeb-query-filter-builder/health.svg)

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

###  Alternatives

[ambengers/query-filter

Laravel package for filtering resources with request query string

3513.5k](/packages/ambengers-query-filter)[hashemi/queryfilter

A simple &amp; dynamic package for your eloquent query in laravel. It will help you to write query logic individual for each parameter.

391.1k](/packages/hashemi-queryfilter)[tapp/filament-value-range-filter

Filament country code field.

2362.2k](/packages/tapp-filament-value-range-filter)[webbingbrasil/filament-datefilter

Date filter component for filament tables.

1479.4k](/packages/webbingbrasil-filament-datefilter)

PHPackages © 2026

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