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

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

heroicpixels/filterable
=======================

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

5786.6k—10%2[3 issues](https://github.com/heroicpixels/filterable/issues)[1 PRs](https://github.com/heroicpixels/filterable/pulls)PHP

Since Dec 12Pushed 9y ago7 watchersCompare

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

READMEChangelogDependenciesVersions (1)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": {
    "heroicpixels/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(
    \\...
    'Heroicpixels\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 'Heroicpixels\\Filterable\\Filterable'.

```
class Object extends Heroicpixels\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 Heroicpixels\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

32

—

LowBetter than 72% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity42

Moderate usage in the ecosystem

Community14

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.6% 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0a1d3d0afd726bc96ffb979217cdaa00e4c3e8f357c3ff33884cbf4cfc24bba6?d=identicon)[heroicpixels](/maintainers/heroicpixels)

---

Top Contributors

[![heroicpixels](https://avatars.githubusercontent.com/u/6350892?v=4)](https://github.com/heroicpixels "heroicpixels (31 commits)")[![wesrice](https://avatars.githubusercontent.com/u/397711?v=4)](https://github.com/wesrice "wesrice (3 commits)")[![threesquared](https://avatars.githubusercontent.com/u/892142?v=4)](https://github.com/threesquared "threesquared (1 commits)")

### Embed Badge

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

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

###  Alternatives

[ruflin/elastica

Elasticsearch Client

2.3k50.4M203](/packages/ruflin-elastica)[opensearch-project/opensearch-php

PHP Client for OpenSearch

15224.3M65](/packages/opensearch-project-opensearch-php)[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[massive/search-bundle

Massive Search Bundle

721.4M13](/packages/massive-search-bundle)[shyim/opensearch-php-dsl

OpenSearch/Elasticsearch DSL library

175.9M9](/packages/shyim-opensearch-php-dsl)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

45802.7k3](/packages/outl1ne-nova-multiselect-filter)

PHPackages © 2026

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