PHPackages                             goopil/eloquent-rest-filter - 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. goopil/eloquent-rest-filter

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

goopil/eloquent-rest-filter
===========================

set of eloquent scopes to implements various rest query strings

0.2.2(7y ago)16[2 PRs](https://github.com/Goopil/laravel-rest-filter/pulls)MITPHPPHP &gt;=7.0.0

Since Mar 18Pushed 7y ago1 watchersCompare

[ Source](https://github.com/Goopil/laravel-rest-filter)[ Packagist](https://packagist.org/packages/goopil/eloquent-rest-filter)[ Docs](https://gitlab.com/goopil/lib/laravel/rest-filter)[ RSS](/packages/goopil-eloquent-rest-filter/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (6)Versions (7)Used By (0)

[![Latest Version on Packagist](https://camo.githubusercontent.com/54eb81c091aa280495dcd1a858e06ffaf9ca90a1baa2a67df0708eb51b746147/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f676f6f70696c2f656c6f7175656e742d726573742d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/goopil/eloquent-rest-filter)[![License](https://camo.githubusercontent.com/f45d904953153ca304a2328243d2733e095eee13a631a1f390709885d41dd692/68747470733a2f2f706f7365722e707567782e6f72672f6c61726176656c2f6672616d65776f726b2f6c6963656e73652e737667)](https://gitlab.com/goopil/lib/laravel/rest-filter/blob/master/LICENSE)[![Build Status](https://camo.githubusercontent.com/6b9051769b42e41b2f41dbd2f72365774d5126c42b0328b550be65fbed6a7880/68747470733a2f2f7472617669732d63692e6f72672f476f6f70696c2f6c61726176656c2d726573742d66696c7465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/Goopil/laravel-rest-filter)[![Coverage Status](https://camo.githubusercontent.com/66b0137b89d15cc4d2ac0fa1931b3a9188d15e0e9751e3241e48ebf2b460c2ee/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f476f6f70696c2f6c61726176656c2d726573742d66696c7465722f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/Goopil/laravel-rest-filter?branch=master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/deee75ac02ff23f2c7a9029f49554ca00a0a4857af95b972df6115908b6c5cf7/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f476f6f70696c2f6c61726176656c2d726573742d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/Goopil/laravel-rest-filter/?branch=master)[![StyleCI](https://camo.githubusercontent.com/20cd6bfd37e0c67b3da3433ef2c20eca691f02b70c886601f6030a92391fb2ab/68747470733a2f2f7374796c6563692e696f2f7265706f732f3132353931373535362f736869656c643f6272616e63683d6d6173746572)](https://styleci.io/repos/125917556)[![Maintainability](https://camo.githubusercontent.com/8d0d572bda2e82f3b4d7ffb3a2553bdff26bac8e51431e4785a1c6d12a3f8004/68747470733a2f2f6170692e636f6465636c696d6174652e636f6d2f76312f6261646765732f30343539303961343931653037336462663136652f6d61696e7461696e6162696c697479)](https://codeclimate.com/github/Goopil/laravel-rest-filter/maintainability)

Rest api scopes
===============

[](#rest-api-scopes)

This package map some usual REST query filters to [Eloquent](https://laravel.com/docs/5.3/eloquent) scopes. This is mainly an extract of the filters present in [andersao/l5-repository](https://github.com/andersao/l5-repository). but attachable to the model itself not via repositories. A big thanks to the previous contributors for their great work ;)

it consist of different scopes &amp; an execution heap to ease the registration. you can register any scope individually or use the heap to register them all. head up: if you use them individually, the Request is a mandatory constructor parameter.

- [Search](#search)
- [Filter](#filter)
- [Sort](#sort)
- [Include](#include)
- [Pagination](#pagination)
- [In / not in](#in-notin)
- [Range selector](#range-selector)
-

you can use [qs](https://github.com/ljharb/qs) to ease the parameters formatting

installation
------------

[](#installation)

install the package

`composer require goopil/eloquent-rest-filter`

> for laravel &lt;= 5.3 add `\Goopil\RestFilter\RestScopeProvider::class` to use the config file

publish config
--------------

[](#publish-config)

you can publish it with `php artisan vendor:publish --provider="Goopil\RestFilter\RestScopeProvider" --tag=config`

declaration
-----------

[](#declaration)

To register all defined query Scopes, you can define the scopes for each query or on the controller to work on a routes basis.

### In Controllers

[](#in-controllers)

```
use App\User;
use Goopil\RestFilter\RestScopes\Scopes\FullScope;

MyController extends Controller
{
    public function __construct()
    {
        // global constructor registration
        User::addGlobalScope(new FullScope);
    }

    public function index (MyCustomRequest $r)
    {
        // you can pass the current request if you use it in your context and specify
        the separator used for this controller only
        User::addGlobalScope(new FullScope($r, ';', '|'));

        // or the request will automaticaly be fetched if none are provided.
        User::addGlobalScope(new FullScope);

        return response()->json([
            data => User::all()
        ]);
    }
 }
```

### In Models

[](#in-models)

> manually

```
use Illuminate\Database\Eloquent\Model as Eloquent;
use Goopil\RestFilter\RestScopes\Scopes\FullScope;

MyModel extends Eloquent
{
    public static function boot ()
    {
        parent::boot();
        static::addGlobalScope(new FullScope);
    }
}
```

> via a trait

```
use Illuminate\Database\Eloquent\Model as Eloquent;
use Goopil\RestFilter\Contracts\Queryable;

MyModel extends Eloquent
{
    use Queryable;
}
```

query syntax
============

[](#query-syntax)

### parameters format

[](#parameters-format)

The parameters support array parameters. `http://exemple.com/api/v1/users?search[1]=John&search[2]=Tom`

### delimiter

[](#delimiter)

valuefunction`;`delimit per field name and query value``search
------

[](#search)

the search feature make use of `Goopil\RestFilter\Contracts\Searchable`. this interface simply specify a `searchable()` method on the model. That will return an array of fields to search into. Relations fields are supported. By default or where clause ar implemented if you want to force a where close, you can add a `!` on the comparison segments

#### searchable method

[](#searchable-method)

```
    static public function searchable()
    {
        return [
            'id',
            'active',
            'username',
            'email',
            'firstname',
            'lastname',
            'roles.name',
            'roles.slug',
            'roles.description',
        ];
    }
```

##### Single value on registered searchable fields

[](#single-value-on-registered-searchable-fields)

`http://exemple.com/api/v1/users?search[]=John%20Doe`

##### Single value on registered nested searchable fields

[](#single-value-on-registered-nested-searchable-fields)

`http://exemple.com/api/v1/users?search[roles.name]=administrator`

##### Single value on registered searchable fields with comparison operator

[](#single-value-on-registered-searchable-fields-with-comparison-operator)

`http://exemple.com/api/v1/users?search[]=Johns;like`

##### Single value on specific field with comparison operator

[](#single-value-on-specific-field-with-comparison-operator)

`http://exemple.com/api/v1/users?search[email]=john@gmail.com;like`

##### multi fields search

[](#multi-fields-search)

`http://exemple.com/api/v1/users?search[name]=John%20Doe&search[email]=john@gmail.com`

##### multi fields search with per field comparison operator

[](#multi-fields-search-with-per-field-comparison-operator)

`http://exemple.com/api/v1/users?search[name]=john&search;like&search[email].com;like`

##### multi fields search with per field comparison operator and force where parameter

[](#multi-fields-search-with-per-field-comparison-operator-and-force-where-parameter)

`http://exemple.com/api/v1/users?search[name]=john&search;like&search[email].com;!like`

filter
------

[](#filter)

`http://exemple.com/api/v1/users?filter=id;name`

nametypeformatfilterstring{field1} ; {value1}sort
----

[](#sort)

`http://exemple.com/api/v1/users?filter=id;name&orderBy=id&sortedBy=desc`

nametypeformatorderBystring{field1}sortedBystring{desc}include
-------

[](#include)

`http://exemple.com/api/v1/users?include=roles``http://exemple.com/api/v1/users?include=roles;sessions``http://exemple.com/api/v1/users?include=roles.permissions;sessions`

nametypeformatincludestring{field1} ; {value1}pagination
----------

[](#pagination)

The `Goopil\RestFilter\Contracts\Paginable` rewrite the static `all()` method to parse the request for `page` &amp; `perPage` params and call the `paginate()` method instead if needed.

`http://exemple.com/api/v1/users?page=1``http://exemple.com/api/v1/users?page=1&perPage=20`

nametypedefaultpageint1perPageint15##### output

[](#output)

as per laravel pagination

```
{
    "total": 53,
    "per_page": "1",
    "current_page": 1,
    "last_page": 53,
    "next_page_url": "http:\/\/exemple.com\/api\/v1\/users?page=2",
    "prev_page_url": null,
    "from": 1,
    "to": 1,
    "data": [{
      ...
     }]
}
```

in notIn
--------

[](#in-notin)

##### simple

[](#simple)

`http://exemple.com/api/v1/users?in=1;2;3;4;5;6`

nametypeformatinidsstring with delimiter or array of int##### exclusive in notIn filter

[](#exclusive-in-notin-filter)

The `notIn` array has precedence over the `in` array `http://exemple.com/api/v1/users?in=1;2;3;4;5;6&notIn=2`

```
 [
     { "name": "user1", "id": 1 },
     { "name": "user3", "id": 3 },
    ...
 ]
```

namefieldformatinidstring with delimiter or array of intnotInidstring with delimiter or array of intrange selector
--------------

[](#range-selector)

`http://exemple.com/api/v1/users?offset=10``http://exemple.com/api/v1/users?limit=20``http://exemple.com/api/v1/users?offset=10&limit=20`

namefieldformatdefaultoffsetidint1limitidint15bugs
----

[](#bugs)

If you find a bug or want to report somethings just drop an issue.

contributions
-------------

[](#contributions)

Contributions are very welcome. Just fork it and do a PR.

###  Health Score

23

↑

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~126 days

Total

3

Last Release

2725d ago

PHP version history (2 changes)0.2.0PHP &gt;=5.5.9

0.2.1PHP &gt;=7.0.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/134531961ce2cc585d7b0248a4f614fa1770c739746fe46698883e3b83dfd845?d=identicon)[goopil](/maintainers/goopil)

---

Top Contributors

[![Goopil](https://avatars.githubusercontent.com/u/9719874?v=4)](https://github.com/Goopil "Goopil (64 commits)")

---

Tags

apilaraveldatabaseeloquentfilterdb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/goopil-eloquent-rest-filter/health.svg)

```
[![Health](https://phpackages.com/badges/goopil-eloquent-rest-filter/health.svg)](https://phpackages.com/packages/goopil-eloquent-rest-filter)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k7.2M71](/packages/mongodb-laravel-mongodb)[illuminate/database

The Illuminate Database package.

2.8k52.4M9.4k](/packages/illuminate-database)[silber/bouncer

Eloquent roles and abilities.

3.6k4.4M25](/packages/silber-bouncer)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[pdphilip/elasticsearch

An Elasticsearch implementation of Laravel's Eloquent ORM

145360.2k4](/packages/pdphilip-elasticsearch)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
