PHPackages                             cyd622/laravel-filterable - 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. cyd622/laravel-filterable

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

cyd622/laravel-filterable
=========================

Laravel package for dynamically filtering Eloquent results using URL query string.

v1.0.0(8y ago)110MITPHPPHP &gt;=5.3.0

Since May 31Pushed 8y agoCompare

[ Source](https://github.com/cyd622/laravel-filterable)[ Packagist](https://packagist.org/packages/cyd622/laravel-filterable)[ RSS](/packages/cyd622-laravel-filterable/feed)WikiDiscussions master Synced yesterday

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

Filterable
==========

[](#filterable)

This package gives you a convenient way to automatically filter Eloquent results based on query string parameters in the URL. Filterable parses the query string, compares it with columns that you'd like to automatically filter, then creates a dynamic scope that is used by Eloquent to construct the SQL.

- [Installation](#installation)
- [Copyright &amp; License](#license)
- [Usage](#usage)
    - [Single Value](#single-value)
    - [Multiple Values](#multiple-values)
    - [Multiple Parameters](#multiple-parameters)
    - [Boolean Operators](#boolean-operators)
    - [Comparison Operators](#comparison-operators)

Installation
====================================================

[](#installation)

Add the package to 'require' in your composer.json file:

```
"require": {
    "cyd622/laravel-filterable": "dev-master"
},

```

Run 'composer dump-autoload' from the command line:

```
#composer dump-autoload

```

Register the service provider in 'app/config/app.php'. Service provider:

```
'providers' => array(
    \\...
    'Laravel\Filterable\FilterableServiceProvider',
    \\...
);

```

License
==========================================

[](#license)

Copyright 2014 Dave Hodgins Released under MIT license (). See LICENSE file for details. Usage
===================================================================================================================================================================

[](#copyright-2014-dave-hodginsreleased-under-mit-license-httpopensourceorglicensesmit--see-license-file-for-detailsusage)

NOTE: this package also includes a version (**FilterableWrapper.php**) that can be used to wrap a DB or Eloquent object, and a version (**FilterableTrait.php**) that can be used as a trait with an Eloquent model.

**Filterable.php**

Edit your Eloquent model to extend 'Laravel\\Filterable\\Filterable'.

```
class Object extends Laravel\Filterable\Filterable {
    // ...
}

```

**FilterableWrapper.php**

Give FilterableWrapper a DB or Eloquent object.

```
$object = DB::table('objects');
$objects = FilterableWrapper($object);

```

**FilterableTrait.php**

```
class Object extends Eloquent {

   use Laravel\Filterable\FilterableTrait;

}

```

The examples below use the Filterable class!

In the above example, class Object corresponds to table 'objects':

idcolorshapetotal1redsquare1502bluesquare20003greencircle5754yellowtriangle155redtriangle9006redtriangle600Filterable Columns
------------------

[](#filterable-columns)

Specify the column you want to automatically filter.

```
$columns = [ 'color', 'shape', 'total' ];

```

For example:

```
 http://www.your-site/?color=blue&shape=round&total=500

```

You can also alias the columns if you prefer not to reveal them:

```
$columns = [ 'col' => 'color', 'sha' => 'shape', 'tot' => 'total' ];

```

For example:

```
http://www.your-site/?col=blue&sha=round&tot=500

```

To filter results, simply pass the columns to Eloquent using filterColumns():

```
$objects = Object::filterColumns($columns)->get()->toArray();

```

You can also filter joins:

```
$columns = array('color' => 'objects.color',
                 'name' => 'objects.name',
                 'shape' => 'objects.shape',
                 'category' => 'cat_object.cat_id');
$objects = Object::join('cat_object', 'objects.id', '=', 'cat_object.object_id')
                   ->filterColumns($columns)
                   ->get()->toArray();

```

And you can filter eager loads:

```
/**
 * Columns available in main query
 */
$columns = array('color' => 'objects.color',
                 'name' => 'objects.name',
                 'shape' => 'objects.shape');
$objects = Object::with(array('categories' => function($q) {
               /**
                * Columns available to sub-query
                */
               $columns = array('category' => 'cat_object.cat_id');
               $q->filterColumns($columns);
           }))->filterColumns($columns)
           ->get()
           ->toArray();

```

The following examples demonstrate how query string parameters can be used. Single Value
--------------------------------------------------------------------------------------------------------------------------------

[](#the-following-examples-demonstrate-how-query-string-parameters-can-be-usedsingle-value)

```
?color=red

SELECT ... WHERE ... color = 'red'

```

idcolorshapetotal1redsquare1505redtriangle9006redtriangle600Multiple Values---

```
?color[]=red&color[]=blue

SELECT ... WHERE ... color = 'red' OR color = 'blue'

```

idcolorshapetotal1redsquare1502bluesquare20005redtriangle9006redtriangle600Multiple Parameters---

```
?color[]=red&shape[]=triangle

SELECT ... WHERE ... color = 'red' AND shape = 'triangle'

```

idcolorshapetotal5redtriangle9006redtriangle600Boolean Operators---

```
?color[]=red&shape[]=triangle&bool[shape]=or

SELECT ... WHERE ... color = 'red' OR shape = 'triangle'

```

idcolorshapetotal4yellowtriangle155redtriangle9006redtriangle600Comparison Operators---

**Greater Than**

```
?total=599&operator[total]=>

SELECT ... WHERE ... total > '599'

```

idcolorshapetotal2bluesquare20005redtriangle9006redtriangle600**Less Than**

```
?total=600&operator[total]=<

SELECT ... WHERE ... total < '600'

```

idcolorshapetotal1redsquare1503greencircle5754yellowtriangle15**Not Equal**

```
?shape=triangle&operator[shape]=!=

SELECT ... WHERE ... shape != 'triangle'

```

idcolorshapetotal4yellowtriangle155redtriangle9006redtriangle600**Between**

```
?total[start]=900&total[end]=5000

SELECT ... WHERE ... total BETWEEN '900' AND '5000'

```

idcolorshapetotal2bluesquare20005redtriangle900

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity58

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

Unknown

Total

1

Last Release

2953d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/46557758?v=4)[tonywang](/maintainers/tonywang)[@tonywang](https://github.com/tonywang)

---

Top Contributors

[![cyd622](https://avatars.githubusercontent.com/u/25097502?v=4)](https://github.com/cyd622 "cyd622 (1 commits)")

---

Tags

laraveldatabaseeloquentLaravel 4

### Embed Badge

![Health badge](/badges/cyd622-laravel-filterable/health.svg)

```
[![Health](https://phpackages.com/badges/cyd622-laravel-filterable/health.svg)](https://phpackages.com/packages/cyd622-laravel-filterable)
```

###  Alternatives

[mongodb/laravel-mongodb

A MongoDB based Eloquent model and Query builder for Laravel

7.1k8.0M90](/packages/mongodb-laravel-mongodb)[baum/baum

Baum is an implementation of the Nested Set pattern for Eloquent models.

2.2k1.6M55](/packages/baum-baum)[spiritix/lada-cache

A Redis based, automated and scalable database caching layer for Laravel

592452.8k2](/packages/spiritix-lada-cache)[ntanduy/cloudflare-d1-database

Cloudflare D1 database driver for Laravel — full Eloquent &amp; Query Builder support.

266.8k](/packages/ntanduy-cloudflare-d1-database)[lemaur/eloquent-publishing

207.8k1](/packages/lemaur-eloquent-publishing)

PHPackages © 2026

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