PHPackages                             aros/omnifetch-lumen - 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. [API Development](/categories/api)
4. /
5. aros/omnifetch-lumen

ActiveLibrary[API Development](/categories/api)

aros/omnifetch-lumen
====================

Lumen Fetching Library for simplifying fetch API endpoints

v0.2.3(5mo ago)2933↑15.4%1MITPHPPHP &gt;=7.0

Since Sep 2Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/lordrah/omnifetch-lumen)[ Packagist](https://packagist.org/packages/aros/omnifetch-lumen)[ Docs](https://github.com/lordrah/omnifetch-lumen)[ RSS](/packages/aros-omnifetch-lumen/feed)WikiDiscussions master Synced today

READMEChangelog (4)DependenciesVersions (7)Used By (0)

OmniFetch for Lumen
===================

[](#omnifetch-for-lumen)

OmniFetch for Lumen is a useful library which makes fetch API endpoints easier to set up and flexible enough for different situations. The library allows for easy modification of the response data set on the fly by passing in query parameters as part of the request. These modifications can range from apply filters, embedding related data and pagination to aggregating data with group bys.

[![Total Downloads](https://camo.githubusercontent.com/15f3dbbaa5d144b678efc9e4e0898423182a3b752e6fdc072e73fb32b314ea9d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61726f732f6f6d6e6966657463682d6c756d656e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aros/omnifetch-lumen)

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

[](#installation)

```
$ composer require aros/omnifetch-lumen

```

Dependencies
------------

[](#dependencies)

- Lumen &gt;= 5.5

Main Functionalities
--------------------

[](#main-functionalities)

OmniFetch has only two methods that can be used. They are the following:

- **OmniFetch::getSingle**(Illuminate\\Database\\Eloquent\\Builder $builder, array $params) - *used to fetch a single record.*
- **OmniFetch::paginate**(Illuminate\\Database\\Eloquent\\Builder $builder, array $params) - *used to fetch a list of records*

The builder being used should be created using a model (i.e. primary model). e.g. `Author::query()`

Parameter Options
-----------------

[](#parameter-options)

The **OmniFetch::getSingle** and **OmniFetch::paginate** both require the **$params** in their arguments which is an associative array of options.

- **filters** (data type: JSON list /array): Adds criteria to the query. It can take as many criteria as required. Each criterion is a JSON object (if *filters* is a JSON list, this format is best if it is passed as a request query parameter) or an associative array (if *filters* is an array). It contains the following fields:

    - *field* (required): the field used for the filtering. It can be a field from the primary model or a related model (which can be done by indicating the relation name specified in the primary model followed by the relation's field. e.g. \*author.rating \*). It supports nested relations fields e.g. *author.publisher.is\_local*.
    - *value* (required): the value to be used.

    > **Note**: if **%** is used in the value it needs to be URL encoded if it is passed as a request query parameter.

    - *cond\_op* (optional | default: '*=*'): the conditional operator used in comparing the field and value. The available operators are: =, !=, &gt;, &lt;, &gt;=, &lt;=, LIKE, IS\_NULL (only *field* is needed), IS\_NOT\_NULL (only *field* is needed).
    - *logical\_op* (optional | default: '*AND*'): the logical operator used to combine the remaining filters after it. The available operators are AND and OR.

    *Examples*:

    - `[{"field": "status_id", "value": 1}]`=&gt; `... WHERE primary_table.status_id = 1;`
    - `[{"field": "name", "value": "%25rich%25", "cond_op": "LIKE"}]`=&gt; `... WHERE primary_table.name LIKE "%rich%";`
    - `[{"field": "status_id", "value": 1}, {"field": "author.rating": "value": 2.5, "cond_op": ">="}]`=&gt; `... WHERE primary_table.status_id = 1 AND author.rating >= 2.5`
    - `[{"field": "likes", "value": 100, "cond_op": ">", "logical_op": "OR"}, {"field": "rating", "value": 4.0, "cond_op": ">="}, {"field": "rating", "value": 4.5, "cond_op": "
