Download the PHP package bugloos/query-filter-bundle without Composer
On this page you can find all versions of the php package bugloos/query-filter-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bugloos/query-filter-bundle
More information about bugloos/query-filter-bundle
Files in bugloos/query-filter-bundle
Package query-filter-bundle
Short Description 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.
License MIT
Informations about the package query-filter-bundle
Query Filter Bundle
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
Compatibility
- PHP v7.4 or above
- Symfony v4.4 or above
Usage
Suppose our database has the following tables with the following relations
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:
You just need to add QueryFilter class in controller:
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.
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
For example we want to filter Book entity by its Country name. Book has ManyToOne relation with Country entity
The following code is in Book controller.
NOTE: There is no need to add your relationship join in Query builder because if join is not added, I will add it automatically. ;)
If you want to filter the ManyToMany relation field or two level deep relation, you should again add mapper
For example we want to filter Book entity by its Writers age. Book has ManyToMany relation with User entity
The following code is in Book controller.
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:
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:
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
Contributing
If you find an issue, or have a better way to do something, feel free to open an issue or a pull request.
All versions of query-filter-bundle with dependencies
doctrine/doctrine-bundle Version ^2.2
doctrine/orm Version ^2.8
symfony/http-kernel Version ^4.4 | ^5.4 | ^6.0
psr/cache Version ^1.0 | ^2.0 | ^3.0
symfony/orm-pack Version ^2.2
symfony/framework-bundle Version ^4.4 | ^5.4 | ^6.0
doctrine/annotations Version ^2.0