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

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

aqjw/filterable
===============

The `Filterable` package is designed for Laravel 8.x+ and provides tools for creating and managing filters for Eloquent models. It makes it easy to scale filters and apply them to filter records.

1.5.0(3y ago)15106MITPHPPHP ^8.1

Since Feb 24Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (5)Used By (0)

Filterable 📝
============

[](#filterable-)

[![Latest Version on Packagist](https://camo.githubusercontent.com/83cc9f13618f0e94def7f10a6bda1033d7a84d7cbbf34a78d55921ab7be38588/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61716a772f66696c74657261626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aqjw/filterable)[![Total Downloads](https://camo.githubusercontent.com/dab7c0ede743a85f7599f9d4f42daa33aa4f3c0b7c1f53a0151a6a535e7f0760/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61716a772f66696c74657261626c652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/aqjw/filterable)

The `Filterable` package is designed for Laravel 8.x+ and provides tools for creating and managing filters for Eloquent models. It makes it easy to scale filters and apply them to filter records.

Get Started 🚀
-------------

[](#get-started-)

### Installation

[](#installation)

The package can be easily installed via Composer using the following command:

```
composer require aqjw/filterable
```

### Adding the `HasFilters` Trait

[](#adding-the-hasfilters-trait)

After installation, add the `HasFilters` trait to the model that you want to filter:

```
use Aqjw\Filterable\HasFilters;

class Product
{
    use HasFilters;
```

Usage
-----

[](#usage)

### Create a filter

[](#create-a-filter)

To create a new filter, use the Artisan `make:filter` command:

```
php artisan make:filter ByPrice
```

You can also specify the column to be filtered:

```
php artisan make:filter ByPrice --column=retail_price
```

In addition, you can specify a group for the filter:

```
php artisan make:filter ByCategory --group=Product
```

The filter will then be created in the following group folder: `\App\Filters\Product\ByCategory::class`

### Applying Filters

[](#applying-filters)

Once you have created your filters, you can apply them to your model:

```
Product::filters([
    \App\Filters\ByPrice::class,
    \App\Filters\BySalePrice::class,
])->get();
```

You can use the `or` operator to apply multiple filters:

```
Product::filters([
    \App\Filters\ByPrice::class,
    'or',
    \App\Filters\BySalePrice::class,
])->get();
```

If you need to group filters, you can wrap them in an array:

```
Product::filters([
    [
        \App\Filters\ByCategory::class,
        \App\Filters\Product\ByPrice::class,
    ],
    'or',
    [
        \App\Filters\BySubCategory::class,
        \App\Filters\BySalePrice::class,
    ],
])->get();
```

### Checking Request Parameters with the `key` Method

[](#checking-request-parameters-with-the-key-method)

The `key` method in the filter class is used to check if a certain key exists in the request parameters. If the key is not present, the filter will not be applied.

Here is an example of how the `key` method can be used:

```
use Aqjw\Filterable\Filter;

class ByPrice extends Filter
{
    public function key()
    {
        // only apply the filter if 'price' is present in the request
        return 'price';
    }

    public function apply($query, $value)
    {
        $query->where('price', $value);
    }
}
```

In this example, the `ByPrice` filter will only be applied if the `price` key is present in the request parameters.

### Overriding the `isActive` Method

[](#overriding-the-isactive-method)

If you want to force a filter to be applied even if the corresponding key is not present in the request parameters, you can override the `isActive` method in the filter class.

Here is an example of how the `isActive` method can be used:

```
use Aqjw\Filterable\Filter;

class ByCategory extends Filter
{
    public function key()
    {
        // only apply the filter if 'category' is present in the request
        return 'category';
    }

    public function isActive($request)
    {
        // always force the filter to be applied,
        //  even if 'category' is not present in the request.
        // this will be useful when we want to apply the filter by default,
        //  for example, when displaying all products in a certain category
        return true;
    }

    public function apply($query, $value)
    {
        if ($value) {
            // apply the filter based on the value of 'category' in the request
            $query->where('category', $value);
        } else {
            // if 'category' is not present in the request, default to showing products in the root category (category ID of 1)
            $query->where('category', 1);
        }
    }
}
```

In this example, the `ByCategory` filter will always be applied, even if the `category` key is not present in the request parameters. If the `category` key is present, the filter will be applied based on its value. If the `category` key is not present, the filter will default to showing products in the root category (category ID of 1).

License
-------

[](#license)

The `Filterable` package is open-sourced software licensed under the MIT License. Please see the [License File](/LICENSE) for more information.

Contributing
------------

[](#contributing)

Contributions are welcome! If you would like to contribute to this project, please follow these steps:

1. Fork the repository
2. Create a new branch (`git checkout -b feature/your-feature`)
3. Make your changes
4. Push your branch to your forked repository (`git push origin feature/your-feature`)
5. Open a pull request

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Every ~17 days

Total

4

Last Release

1126d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/3bbc50eee573168342cf8eaa53bcc09048939b7dc4bb79187133c919ce6e1e8b?d=identicon)[aqjw](/maintainers/aqjw)

---

Top Contributors

[![aqjw](https://avatars.githubusercontent.com/u/13101908?v=4)](https://github.com/aqjw "aqjw (14 commits)")

---

Tags

laravelfilterfilter records

### Embed Badge

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

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

###  Alternatives

[awesome-nova/filter-card

A Laravel Nova card.

25126.1k](/packages/awesome-nova-filter-card)[pos-lifestyle/laravel-nova-date-range-filter

A Laravel Nova date range filter.

16179.1k](/packages/pos-lifestyle-laravel-nova-date-range-filter)[tapp/filament-value-range-filter

Filament country code field.

2362.2k](/packages/tapp-filament-value-range-filter)[webbingbrasil/filament-datefilter

Date filter component for filament tables.

1479.4k](/packages/webbingbrasil-filament-datefilter)[ambengers/query-filter

Laravel package for filtering resources with request query string

3513.5k](/packages/ambengers-query-filter)

PHPackages © 2026

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