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

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

ralphmorris/laravel-query-filter
================================

A packages to help create filters to queries based on request parameters

239PHPCI failing

Since Dec 3Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ralphmorris/laravel-query-filter)[ Packagist](https://packagist.org/packages/ralphmorris/laravel-query-filter)[ RSS](/packages/ralphmorris-laravel-query-filter/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (1)Used By (0)

Laravel Query Filter
====================

[](#laravel-query-filter)

Easily add dedicated filters based on request parameters. Originally came from a great tutorial on Laracasts. After copying it from project to project a few times I've now put it into a little package and added a generator for ease of use.

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

[](#installation)

You can install the package via composer:

```
composer require ralphmorris/laravel-query-filter
```

Usage
-----

[](#usage)

To allow a model to be filterable, first add the FilterableTrait to your model.

```
use Illuminate\Database\Eloquent\Model;
use RalphMorris\LaravelQueryFilter\FilterableTrait;

class Post extends Model
{
    use FilterableTrait;
}
```

Then to create your filter class run the command below.

```
php artisan make:filter PostFilters
```

This will place the filter class under an App\\Filters namespace if you are using the default namespace/directory structure. It should look like this.

```
namespace App\Filters;

use RalphMorris\LaravelQueryFilter\QueryFilter;

class PostFilters extends QueryFilter
{
    /**
     * Example
     *
     * The request parameter key as the method name.
     * Passes the parameters value to the method
     * so we can apply a filter to the query.
     *
     * @param  mixed $param Value of the request parameter
     */
    public function example_request_param($param)
    {
        $this->builder->where('example_request_param', $param);
    }
}
```

If you wanted to add a filter on the title and author ID, you might do something like this.

```
namespace App\Filters;

use RalphMorris\LaravelQueryFilter\QueryFilter;

class PostFilters extends QueryFilter
{
    public function title($title)
    {
        $this->builder->where('title', 'like', "%{$title}%");
    }

    public function author($authorId)
    {
        $this->builder->where('author_id', $authorId);
    }
}
```

Finally to add the filters to your query apply filter() query scope in the FilterableTrait to your query and pass the PostFilters class through.

```
public function index(PostFilters $filters)
{
    $posts = Post::filter($filters)->get();
}
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ralph Morris](https://github.com/ralphmorris)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

Laravel Package Boilerplate
---------------------------

[](#laravel-package-boilerplate)

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).

###  Health Score

20

—

LowBetter than 14% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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.

### Community

Maintainers

![](https://www.gravatar.com/avatar/c53ed5cf2c3fd9656db22c058a77be537cbb3c4a8fb91c0af469ee42675b6d01?d=identicon)[ralphmorris](/maintainers/ralphmorris)

---

Top Contributors

[![ralphmorris](https://avatars.githubusercontent.com/u/12704880?v=4)](https://github.com/ralphmorris "ralphmorris (3 commits)")

---

Tags

filterlaravellaravel-5-packagequeryfilter

### Embed Badge

![Health badge](/badges/ralphmorris-laravel-query-filter/health.svg)

```
[![Health](https://phpackages.com/badges/ralphmorris-laravel-query-filter/health.svg)](https://phpackages.com/packages/ralphmorris-laravel-query-filter)
```

###  Alternatives

[ruflin/elastica

Elasticsearch Client

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

PHP Client for OpenSearch

15024.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)
