PHPackages                             mnabialek/laravel-eloquent-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. mnabialek/laravel-eloquent-filter

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

mnabialek/laravel-eloquent-filter
=================================

Allows filtering Eloquent queries by input filters

v0.1.3(5y ago)2614.5k↓50%11[5 PRs](https://github.com/mnabialek/laravel-eloquent-filter/pulls)MITPHP

Since Jun 12Pushed 2y ago3 watchersCompare

[ Source](https://github.com/mnabialek/laravel-eloquent-filter)[ Packagist](https://packagist.org/packages/mnabialek/laravel-eloquent-filter)[ RSS](/packages/mnabialek-laravel-eloquent-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (5)Versions (13)Used By (0)

Laravel Eloquent Filter
=======================

[](#laravel-eloquent-filter)

[![Build Status](https://camo.githubusercontent.com/33762a485c59f63b3816adf067e89246342b0a03ff6717ac66a01a1e1564ef23/68747470733a2f2f7472617669732d63692e6f72672f6d6e616269616c656b2f6c61726176656c2d656c6f7175656e742d66696c7465722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mnabialek/laravel-eloquent-filter)[![Coverage Status](https://camo.githubusercontent.com/d260c2d099d12bbd1d2740ad4204655b9807a0b0e8c683a89f975cc14255d4d2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d6e616269616c656b2f6c61726176656c2d656c6f7175656e742d66696c7465722f62616467652e737667)](https://coveralls.io/github/mnabialek/laravel-eloquent-filter)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/93ef816f269795dfe25cf87cba8183862d4d6253e3a6eafe230ac1065a850160/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6e616269616c656b2f6c61726176656c2d656c6f7175656e742d66696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mnabialek/laravel-eloquent-filter/badges/quality-score.png?b=master)[![StyleCI](https://camo.githubusercontent.com/44d1772b31a659086ad351c99ad5ae0d44ab207d64a4d092e9e1afdfbdc17743/68747470733a2f2f7374796c6563692e696f2f7265706f732f36303935303932372f736869656c643f7374796c653d666c6174266272616e63683d6d6173746572)](https://styleci.io/repos/60950927)[![Packagist](https://camo.githubusercontent.com/c76d3a6e2b6e6db690001479cae4433e71be02ada0272e3b21ffa30ad56d5ca3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6e616269616c656b2f6c61726176656c2d656c6f7175656e742d66696c7465722e737667)](https://camo.githubusercontent.com/c76d3a6e2b6e6db690001479cae4433e71be02ada0272e3b21ffa30ad56d5ca3/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6e616269616c656b2f6c61726176656c2d656c6f7175656e742d66696c7465722e737667)

This module lets you filter Eloquent data using query filters. You can apply WHERE filters and also set order of results

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

[](#installation)

1. Run

    ```
    composer require mnabialek/laravel-eloquent-filter
    ```

    in console to install this module
2. That's it! Installation is complete. You don't need to adjust any config or install service providers.

Getting started
---------------

[](#getting-started)

Let's assume you want to allow to filter users data. By default you use `User` Eloquent model to get users. To enable filtering, open User model (by default `app/User.php` file) and add into it the following trait:

```
use \Mnabialek\LaravelEloquentFilter\Traits\Filterable;
```

just bellow opening class definition, so it should look something like this:

```
class User extends Authenticatable
{
    use \Mnabialek\LaravelEloquentFilter\Traits\Filterable;
```

To allow filtering for this class, you need to also create implementation of `Mnabialek\LaravelEloquentFilter\Contracts\QueryFilter` interface. To do that create min `app/Filters` directory file with the following content:

```
