Download the PHP package apfelfrisch/query-filter without Composer
On this page you can find all versions of the php package apfelfrisch/query-filter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download apfelfrisch/query-filter
More information about apfelfrisch/query-filter
Files in apfelfrisch/query-filter
Package query-filter
Short Description A Framework agnostic query filter that sorts and filters queries using URL parameters
License MIT
Informations about the package query-filter
Query Filter
This Package provides a Framework agnostic Query Filter wich allows you to filter and sort queries based on the provided URL parameters. It comes with built-in adapters for Eloquent and Doctrine QueryBuilder, but can be extended to support other query building tools as well. The built-in URL parser supports basic JSON API functionality, and can be swapped out for a customized parser if needed.
Yet another query filter - but why?
I was searching for a query-filter that separates the criteria builder from the SQL builder, this way the criteria can be created in one location and then passed to another, which is useful for adding them into repositories. Additionally, I needed the capability to write custom QueryBuilderAdapter for different implementations, mainly for using it with In-Memory Repositories for testing purposes.
Installation
composer require apfelfrisch/query-filter
Basic Usage
Filter Users with the Name John
/users?filter[name]=John
Filter Users with the Name John or Doe
/users?filter[name]=John,Doe
Filter Users with name John and last name Doe
/users?filter[name]=John&filter[lastname]=Doe
Sort Users ascending by name
/users?sort=name
Sort Users ascending by name and descending created_at
/users?sort=name,-created_at
Allow only specfic fields
If needed, you can restrict the selected fields. If you do so, you must specify the fields via URI parameter. In the example below, only name and lastname will be selected.
/users?fields=name,lastname
Skipping forbidden criterias
By default, this package throws an exception if a filter or sort criteria is requested but not allowed. You can silently skip forbidden criterias like so:
Specify FilterCriteria
/users?filter[name]=John
Write a custom Filter
Your customer Filter has to implement the Filter interface. Concrete implementations can be found in the Criterias folder.
If you want to set your Filter as default, you can do it like so:
Write custom QueryParser
todo
Write custom QueryBuilderAdaper
todo