Download the PHP package ricktap/qriteria without Composer
On this page you can find all versions of the php package ricktap/qriteria. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ricktap/qriteria
More information about ricktap/qriteria
Files in ricktap/qriteria
Package qriteria
Short Description Automatic url parameter mapping to sort, filter, include and select data in an easy to use fluent api within Laravel 5. The default parameter structure is compatible to the http://jsonapi.org specification.
License MIT
Homepage https://github.com/ricktap/Qriteria
Informations about the package qriteria
Qriteria
Home of Qriteria: https://github.com/ricktap/Qriteria
Qriteria is a frankenword containing the terms Query and Criteria. It is intended to take the $_GET Parameters of a request and maps the words filter, fields, sort, include and limit as described in the JSON API Specification to the query of an eloquent model.
Qriterias fluent Api allows for three query hooks:
- class based pre-hooks, that are run before every query it sends on every instance of your model
- on-call queries, that are called before the translation but after your pre-hook and only for this one instance object
- method-based queries, those are called after the translation and can be used like a scope method in eloquent
Installation
add the following to your config/app.php inside the providers array
Configuration
To configure Qriteria, you can generate the config/qriteria.php config file by running the command:
Filtering
Syntax:
Result:
Description:
Every filter statement consists of three parts, separated by colons (:). The first part represents the field to query, the second part is the operation, that is available as a symbol or a word (i.e. you can use = or eq for the same thing) the third part is the value to compare to. the filter statements are separated by a comma (,) or a pipe (|). The comma means and the pipe means or. Statements can be wrapped into parenthesis like in a mathematical function, to sort their execution sequence.
Todo
- Write a more exhaustive documentation and maybe even a wiki
- Write more tests
- Have more checks in place
- Map eq to =, lt to <, etc.
- Split the searchable trait into two separate traits. one for filter and one for qriteria itself
- further validate the user input, right now the only thing I'm doing is a check on the parentheses to see if they are balanced and in order