PHPackages                             sheikhheera/requent - 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. [Database &amp; ORM](/categories/database)
4. /
5. sheikhheera/requent

ActiveLibrary[Database &amp; ORM](/categories/database)

sheikhheera/requent
===================

A GraphQL like interface to map a request to eloquent query with data transformation.

1.0.1(9y ago)781716MITPHPPHP &gt;=5.6.4

Since Jun 9Pushed 8y ago3 watchersCompare

[ Source](https://github.com/heera/requent)[ Packagist](https://packagist.org/packages/sheikhheera/requent)[ RSS](/packages/sheikhheera-requent/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (2)Dependencies (6)Versions (4)Used By (0)

Laravel Requent [![Build Status](https://camo.githubusercontent.com/ba5852e81c2052ea0e08c21c0f89b724623e674b78df3264099d9315bb5d0843/68747470733a2f2f7472617669732d63692e6f72672f68656572612f72657175656e742e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/heera/requent) [![Latest Stable Version](https://camo.githubusercontent.com/300d6de167f582fb0406cb9d75878263d632fda71006e3eefeaa1e0e0cdb8404/68747470733a2f2f706f7365722e707567782e6f72672f736865696b6868656572612f72657175656e742f762f737461626c65)](https://packagist.org/packages/sheikhheera/requent) [![GitHub license](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](https://github.com/heera/requent/blob/master/LICENSE)
===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-requent---)

An elegant, light-weight GQL (Graph Query Language) like interface for Eloquent with zero configuration. It maps a request to eloquent query and transforms the result based on query parameters. It also supports to transform the query result explicitly using user defined transformers which provides a more secured way to exchange data from a public API with minimal effort.

- [Installation](#installation)
- [How It Works](#how-it-works)
- [Basic Example](#basic-example)
- [Resource](#resource)
- [Methods](#methods)
- [Resource Key By](#key-by)
- [Data Filtering Using Transformers](#transformer)
- [Get Raw Result](#raw)
- [Query Modifier Clause](#query-clause)
- [Customizations](#customizations)

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

[](#-installation)

You can simply run the following command from your terminal to install the package:

```
composer require sheikhheera/requent

```

Or add the following line in "composer.json" file within "require" section and run `composer install` from terminal:

```
"sheikhheera/requent": "1.0.*"

```

> If you are using version 5.5 or greater, then you are all done, no need to add service provider or alias in `config\app`. So you can simply skip the following steps because of Laravel's package auto discovery feature.

This will install the package. Now add the following entry in your `config/app.php` file inside the `providers` section:

```
Requent\RequentServiceProvider::class

```

Also add the following entry in `aliases` section of your `config/app.php` file:

```
'Requent' => Requent\Facade\Requent::class,

```

If you've done everything right then you can start using it without any configuration but you may customize it.

 How It Works
-----------------------------------------------------

[](#-how-it-works)

This package will allow us to query resources through the request query string parameter. For example, if we've a `User` model and the `User` model has many posts (`Post` model) and each post has many comments (`Comment` model) then we can query the users with their posts and comments of each posts by sending a request like the followig: `http://example.com/users?fields=posts{comments}`. This is the most basic use case but it offers more. We can also select properties of each model through query string, for example, if we want to select only the emal field from the `User` model and title from `Post` and body from the `Comment` model then we can just do it by sending a request using the following `URL`:

```
http://example.com/users?fields=email,posts.orderByDesc(id){title,comments{body}}

```

It'll be translated into something similar to following (Not literally):

```
User::select('email')
->with(['posts' => function($query) {
    $query
    ->orderByDesc('id')
    ->select('title')
    ->with(['comments' => function($query) {
        $query->select('body');
    }])
}]);
```

 Basic Example
-------------------------------------------------------

[](#-basic-example)

To use this package, we need to create some resources (Eloquent Models). For this demonstration, we'll use the same idea using User, Post and Comment models for an imaginary blog. The User model has a `hasMany` relation for posts and the Post model has a `hasMany` relation for comments. So, we need a route, which could be a resourceful route but we'll use an explicite route declaration here:

```
Route::get('users', 'UserController@index');
```

Now, we need a controller which is just a simple controller, for example:

```
