PHPackages                             bugloos/query-filter-bundle - 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. bugloos/query-filter-bundle

ActiveSymfony-bundle[Search &amp; Filtering](/categories/search)

bugloos/query-filter-bundle
===========================

The query filter bundle allows you to filter data from QueryBuilder and the Database. you can filter multiple columns at the same time and also you can filter relation fields with two-level deep and without any join in your query builder.

v1.2.0(2y ago)175.1k2[1 issues](https://github.com/bugloos/query-filter-bundle/issues)[1 PRs](https://github.com/bugloos/query-filter-bundle/pulls)MITPHPPHP &gt;=8.1

Since May 17Pushed 1y ago2 watchersCompare

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

READMEChangelog (10)Dependencies (14)Versions (15)Used By (0)

Query Filter Bundle
-------------------

[](#query-filter-bundle)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/aae2cfc58acb642ddefe2378fb26ea5003aa0e12775fab33ee909669dc389052/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6275676c6f6f732f71756572792d66696c7465722d62756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d61696e)](https://scrutinizer-ci.com/g/bugloos/query-filter-bundle/?branch=main)[![GitHub Workflow Status](https://camo.githubusercontent.com/b7fafc4b14ffd6317e831b3865bf60581a5e8d92867659ff903f896e3507cd7c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f776f726b666c6f772f7374617475732f6275676c6f6f732f71756572792d66696c7465722d62756e646c652f74657374)](https://github.com/bugloos/query-filter-bundle/actions)[![Code Intelligence Status](https://camo.githubusercontent.com/778788c99a949416d67bb57b7a802bda46e6bcafad99e58574ce8fa99c5c3c9f/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6275676c6f6f732f71756572792d66696c7465722d62756e646c652f6261646765732f636f64652d696e74656c6c6967656e63652e7376673f623d6d61696e)](https://scrutinizer-ci.com/code-intelligence)

What does it do? :)
-------------------

[](#what-does-it-do-)

The query filter bundle allows you to filter data from QueryBuilder and the Database. you can filter multiple columns at the same time and also you can filter relation fields with two-level deep and without any join in your query builder. Installation
------------

[](#installation)

```
composer require bugloos/query-filter-bundle
```

Compatibility
-------------

[](#compatibility)

- PHP v7.4 or above
- Symfony v4.4 or above

Usage
-----

[](#usage)

Suppose our database has the following tables with the following relations [![Service running preview](./tests/Fixtures/db/diagram.png)](./tests/Fixtures/db/diagram.png)

**Now we want to filter Book entity**

We want filter Book entity by `title` column, so we can send filter data by Querystring or with array in inline code like this:

```
/*
 * Filter books by title column
*/
//Get api/book/index?filter[title]=text_for_search
OR
$filters = [
    'title' => 'text_for_search',
];
/*
 * Filter books by title column
*/
//Get api/book/index?filter[title]=text_for_search
OR
$filters = [
    'title' => 'text_for_search',
];
```

You just need to add QueryFilter class in controller:

```
use Bugloos\QueryFilterBundle\Service\QueryFilter;
```

The following code is in Book controller.

As you see, At first you should call for() method and pass QueryBuilder as parameter to this method

Then call parameters() method and pass filters request items

At the end you should call filter() method to run it

The return of filter method is Query Builder, so you can add anything else to Query Builder after filtering. ```
public function index(
    Request $request,
    BookRepository $bookRepository,
    QueryFilter $queryFilter
): Response {
    $queryBuilder = $bookRepository->createQueryBuilder('b');

    $queryBuilder = $queryFilter->for($queryBuilder)
        ->parameters($request->get('filters'))
        ->filter()
    ;

    return $queryBuilder->getQuery()->getResult();
}
```

If you want to filter the ManyToOne relation field or one level deep relation, you should add mapper.

To add a mapper, you call addMapper() method to add single mapper or call mappers() method to add multiple mappers with array

First parameter of addMapper() method is parameter name and second parameter is relation name and its field name, which separate by " . " sign

```
$mappers = [
    'country' => 'country.name',
];
```

For example we want to filter Book entity by its Country name. Book has ManyToOne relation with Country entity

```
/*
 * Filter books by country column
*/
//Get api/book/index?filter[country]=text_for_search
OR
$filters = [
    'country' => 'text_for_search',
];
/*
 * Filter books by country column
*/
//Get api/book/index?filter[country]=text_for_search
OR
$filters = [
    'country' => 'text_for_search',
];
```

The following code is in Book controller.

```
public function index(
    Request $request,
    BookRepository $bookRepository,
    QueryFilter $queryFilter
): Response {
    $queryBuilder = $bookRepository->createQueryBuilder('b');

    $queryBuilder = $queryFilter->for($queryBuilder)
        ->parameters($request->get('filters'))
        ->addMapper('country', 'country.name')
        ->filter()
    ;

    return $queryBuilder->getQuery()->getResult();
}
```

**NOTE**: There is no need to add your relationship join in Query builder because if join is not added, I will add it automatically. ;)

```
$queryBuilder = $bookRepository->createQueryBuilder('b');
OR
$queryBuilder = $bookRepository->createQueryBuilder('b')
    ->addSelect('country')
    ->leftJoin('b.country', 'country')
;
```

If you want to filter the ManyToMany relation field or two level deep relation, you should again add mapper

```
$mapper = [
    'age' => 'bookUsers.user.age',
];
```

For example we want to filter Book entity by its Writers age. Book has ManyToMany relation with User entity

```
/*
 * Filter books by Writers age column
*/
//Get api/book/index?filter[age]=31
OR
$filters = [
    'age' => 31,
];
/*
 * Filter books by Writers age column
*/
//Get api/book/index?filter[age]=31
OR
$filters = [
    'age' => 31,
];
```

The following code is in Book controller.

```
public function index(
    Request $request,
    BookRepository $bookRepository,
    QueryFilter $queryFilter
): Response {
    $queryBuilder = $bookRepository->createQueryBuilder('b');

    $queryBuilder = $queryFilter->for($queryBuilder)
        ->parameters($request->get('filters'))
        ->addMapper('age', 'bookUsers.user.age')
        ->sort()
    ;

    return $queryBuilder->getQuery()->getResult();
}
```

**NOTE**: You should know that you can filter data with multiple columns too, you just need to send multiple filter data with a Query string like this:

```
/*
 * Filter books by title and age
*/
//Get api/book/index?filter[title]=text&filter[age]=31
OR
$filters = [
    'title' => 'text',
    'age' => 31,
];
```

Suggestion
----------

[](#suggestion)

You can change two parameters with the config file, just make a yaml file in config/packages/ directory then you can change default cache time for queries and default relation separator as follows:

```
query_filter:
  default_cache_time: 3600
  separator: '.'
```

**NOTE**: You can set the cache time for each query separately and if you don't set any cache time, it uses default cache time in your config file

```
$queryBuilder = $queryFilter->for($queryBuilder)
    ->parameters($request->get('filters'))
    ->cacheTime(120)
    ->sort()
;
```

Contributing [![v](https://camo.githubusercontent.com/4496429c212e92925ad229f392470bef124a63e0f61a79335ad9e3bef49e1c69/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f323730632e706e67)](https://camo.githubusercontent.com/4496429c212e92925ad229f392470bef124a63e0f61a79335ad9e3bef49e1c69/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f323730632e706e67) [![beer](https://camo.githubusercontent.com/b961a5c1314043567b992602ab2031271403c3c5edef139eaf3ccf17a7afd3f5/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f31663337612e706e67)](https://camo.githubusercontent.com/b961a5c1314043567b992602ab2031271403c3c5edef139eaf3ccf17a7afd3f5/68747470733a2f2f6769746875622e6769746875626173736574732e636f6d2f696d616765732f69636f6e732f656d6f6a692f756e69636f64652f31663337612e706e67)
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[](#contributing--)

If you find an issue, or have a better way to do something, feel free to open an issue or a pull request.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 53.6% 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 ~30 days

Recently: every ~63 days

Total

14

Last Release

1066d ago

PHP version history (2 changes)v1.0.0PHP &gt;=7.4

v1.2.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/7392a60c4f5b979291379c2da91de1643142fc43e750f838e5ae198952b8d2b5?d=identicon)[Bugloos](/maintainers/Bugloos)

---

Top Contributors

[![miladghofrani](https://avatars.githubusercontent.com/u/33462687?v=4)](https://github.com/miladghofrani "miladghofrani (15 commits)")[![bugloos](https://avatars.githubusercontent.com/u/16559758?v=4)](https://github.com/bugloos "bugloos (8 commits)")[![mojtaba-gheytasi](https://avatars.githubusercontent.com/u/46230939?v=4)](https://github.com/mojtaba-gheytasi "mojtaba-gheytasi (5 commits)")

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/bugloos-query-filter-bundle/health.svg)

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

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[ec-cube/ec-cube

EC-CUBE EC open platform.

78527.0k1](/packages/ec-cube-ec-cube)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)

PHPackages © 2026

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