PHPackages                             studiow/laravel-filtering - 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. [Search &amp; Filtering](/categories/search)
4. /
5. studiow/laravel-filtering

ActiveLibrary[Search &amp; Filtering](/categories/search)

studiow/laravel-filtering
=========================

Provides a unified filter interface for Collections, Database and Eloquent Queries

v0.0.5(6y ago)0241PHP

Since May 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/studiowbe/laravel-filter)[ Packagist](https://packagist.org/packages/studiow/laravel-filtering)[ RSS](/packages/studiow-laravel-filtering/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (4)Dependencies (4)Versions (6)Used By (1)

laravel-filter
==============

[](#laravel-filter)

Provides a unified filter interface for Collections, Database and Eloquent Queries

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

[](#installation)

The (highly) recommended way to install this package is by using [Composer](https://getcomposer.org/)

```
composer require studiow/laravel-filter
```

Creating
--------

[](#creating)

Use the Filter::make method to create a filter interface:

```
//From a collection
\Studiow\Laravel\Filtering\Filter::make(collect([]));

//From an array (or any datastructure supported by Illuminate\Support\Collection)
\Studiow\Laravel\Filtering\Filter::make([]));

//From an eloquent model query
\Studiow\Laravel\Filtering\Filter::make(ModelName::query());

//From an eloquent model instance
\Studiow\Laravel\Filtering\Filter::make($myModelInstance));

//From a Query Builder
\Studiow\Laravel\Filtering\Filter::make(\DB::table('the_table_name'));
```

Usage
-----

[](#usage)

### Simple filtering

[](#simple-filtering)

```
$collection = collect([
        ['product' => 'Desk', 'price' => 200],
        ['product' => 'Chair', 'price' => 100],
        ['product' => 'Bookcase', 'price' => 150],
        ['product' => 'Door', 'price' => 100],
]);

$filter = \Studiow\Laravel\Filtering\Filter::make($collection);

//add a filter
$filtered = $filter->where('price', 100)->items();

$filtered->all();

/*
    [
        ['product' => 'Chair', 'price' => 100],
        ['product' => 'Door', 'price' => 100],
    ]
*/

//add a filter with an operator
$cheap = $filter->where('price',  '
