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

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

abdallahmohammed/laravel-eloquent-filter
========================================

A simple laravel package to filter models and relations

2.0(4y ago)1310MITPHPPHP &gt;=7.1CI passing

Since Aug 9Pushed 4y agoCompare

[ Source](https://github.com/AbdallaMohammed/laravel-eloquent-filter)[ Packagist](https://packagist.org/packages/abdallahmohammed/laravel-eloquent-filter)[ RSS](/packages/abdallahmohammed-laravel-eloquent-filter/feed)WikiDiscussions master Synced yesterday

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

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

[](#laravel-eloquent-filter)

A simple Laravel, and Lumen package to filter models, and relations

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

[](#installation)

#### Laravel

[](#laravel)

via composer

```
composer require abdallahmohammed/laravel-eloquent-filter:dev-master
```

Edit config/app.php (Skip this step if you are using laravel 5.5+)

```
LaravelEloquentFilter\Providers\LaravelServiceProvider::class,
```

Copy the package config to your local config

```
php artisan vendor:publish --provider="LaravelEloquentFilter\Providers\LaravelServiceProvider"
```

In the `config/laravel-eloquent-filter.php` config file. Set the namespace your model filters will reside in

```
'namespace' => "App\\Http\\Filters\\",
```

#### Lumen

[](#lumen)

> This is only required if you want to use the `php artisan make:filter` command.

In `bootstrap/app.php`

```
$app->register(LaravelEloquentFilter\Providers\LumenServiceProvider::class);
```

##### Change The Default Namespace

[](#change-the-default-namespace)

In `bootstrap/app.php`

```
config(['laravel-eloquent-filter.namespace' => "App\\Http\\Filters\\"]);
```

Usage
-----

[](#usage)

#### Generating the filter

[](#generating-the-filter)

You can create a model filter with the following artisan command

```
php artisan make:filter User
```

Where `User` is the Eloquent Model name you are creating the filter for. This will create `app/Http/Filters/UserFilter.php`

> The command also supports psr-4 namespacing for creating filters.

#### Defining filters

[](#defining-filters)

After generating the filter for an Eloquent Model you will find something like that in the filters directory

```
