PHPackages                             skover/eloquent-builder - 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. skover/eloquent-builder

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

skover/eloquent-builder
=======================

v0.5.1(7y ago)06MITPHPPHP ^7.1

Since Aug 11Pushed 7y agoCompare

[ Source](https://github.com/pskowronek90/eloquent-builder)[ Packagist](https://packagist.org/packages/skover/eloquent-builder)[ RSS](/packages/skover-eloquent-builder/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (5)Versions (8)Used By (0)

Provides a Eloquent query builder for Laravel 5
===============================================

[](#provides-a-eloquent-query-builder-for-laravel-5)

[![Build Status](https://camo.githubusercontent.com/137206bb23e10ab3d046b09cd041833221c92de5fe146f593e724d57b7a2babc/68747470733a2f2f7472617669732d63692e6f72672f6d6f68616d6d61642d666f756c61646761722f656c6f7175656e742d6275696c6465722e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/mohammad-fouladgar/eloquent-builder)[![Coverage Status](https://camo.githubusercontent.com/1dc7de40f94ce4fb8317c8750487dbd2c10f6dbd44ffe447d9f60f5dcac0cf1e/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d6f68616d6d61642d666f756c61646761722f656c6f7175656e742d6275696c6465722f62616467652e7376673f6272616e63683d646576656c6f70)](https://coveralls.io/github/mohammad-fouladgar/eloquent-builder?branch=develop)[![StyleCI](https://camo.githubusercontent.com/0fcb1453630f8cffd2b725ccecdd10f7445e6bbcca8a2ebe6fe589f4f77117d4/68747470733a2f2f6769746875622e7374796c6563692e696f2f7265706f732f3134343336393138382f736869656c643f6272616e63683d646576656c6f70)](https://github.styleci.io/repos/144369188)[![Latest Stable Version](https://camo.githubusercontent.com/6ebbdf454bb3d90aeea663d31fc901b995461806e247eb7d0e05ddb028bc731c/68747470733a2f2f706f7365722e707567782e6f72672f6d6f68616d6d61642d666f756c61646761722f656c6f7175656e742d6275696c6465722f762f737461626c65)](https://packagist.org/packages/mohammad-fouladgar/eloquent-builder)[![Total Downloads](https://camo.githubusercontent.com/dca7957ce9e636f1ee6e41b38e67f2c6abd8991050b2ed101f86e58cc561fd30/68747470733a2f2f706f7365722e707567782e6f72672f6d6f68616d6d61642d666f756c61646761722f656c6f7175656e742d6275696c6465722f646f776e6c6f616473)](https://packagist.org/packages/mohammad-fouladgar/eloquent-builder)[![License](https://camo.githubusercontent.com/c00e354060e912b1cd29110b287ea3e468ee7a1a600b94177b77a72dd1a584b1/68747470733a2f2f706f7365722e707567782e6f72672f6d6f68616d6d61642d666f756c61646761722f656c6f7175656e742d6275696c6465722f6c6963656e7365)](https://packagist.org/packages/mohammad-fouladgar/eloquent-builder)

This package allows you to build eloquent queries, based on request parameters. It greatly reduces the complexity of the queries and conditions, which will make your code cleaner.

### Installation

[](#installation)

```
composer require mohammad-fouladgar/eloquent-builder
```

> Laravel 5.5 uses Package Auto-Discovery, so you are not required to add ServiceProvider manually.

### Laravel &lt;= 5.4.x

[](#laravel--54x)

If you don't use Auto-Discovery, add the ServiceProvider to the providers array in `config/app.php` file

```
'providers' => [
  /*
   * Package Service Providers...
   */
  Fouladgar\EloquentBuilder\ServiceProvider::class,
],
```

And add the **facade** to your `config/app.php` file

```
/*
|--------------------------------------------------------------------------
| Class Aliases
|--------------------------------------------------------------------------
*/
'aliases' => [
    "EloquentBuilder" => Fouladgar\EloquentBuilder\Facade::class,
]
```

### Default Filters Namespace

[](#default-filters-namespace)

The default namespace for all filters is `App\EloquentFilters\` with the base name of the Model.

For example:

Suppose we have a **User** model with an **AgeMoreThan** filter.As a result, the namespace filter must be as follows:

`App\EloquentFilters\User\AgeMoreThanFilter`

#### With Config file

[](#with-config-file)

You can optionally publish the config file with:

```
php artisan vendor:publish --provider="Fouladgar\EloquentBuilder\ServiceProvider" --tag="config"
```

And set the namespace for your model filters which will reside in:

```
return [
    /*
     |--------------------------------------------------------------------------
     | Eloquent Filter Settings
     |--------------------------------------------------------------------------
     |
     | This is the namespace all you Eloquent Model Filters will reside
     |
     */
    'namespace' => 'App\\EloquentFilters\\',
];
```

Usage
-----

[](#usage)

Suppose we want to get the list of the users with the requested parameters as follows:

```
//Get api/user/search?age_more_than=25&gender=male&has_published_post=true
[
    'age_more_than'  => '25',
    'gender'         => 'female',
    'has_published_post' => 'true',
]
```

In the **legacy** code the method written below was followed:

```
