PHPackages                             mjedari/larafilter - 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. mjedari/larafilter

ActiveLibrary

mjedari/larafilter
==================

Simple laravel query string based filter package

1.0.2(4y ago)834MITPHPPHP ^7.4|^8.0

Since Dec 19Pushed 4y ago1 watchersCompare

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

READMEChangelog (3)Dependencies (3)Versions (4)Used By (0)

[![](https://raw.githubusercontent.com/mjedari/larafilter/master/art/banner.png)](https://raw.githubusercontent.com/mjedari/larafilter/master/art/banner.png)

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

[](#laravel-query-string-filter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/29fb60fe486e58af9f5d4e0e2b3b4861ad4fc668e7155d593fd653566af36599/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d6a65646172692f6c61726166696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mjedari/larafilter)[![Build Status](https://camo.githubusercontent.com/1e5a693fed002cdcc38c0596bf35b987c72f7a5496f927c1d3adbcd2032d03ab/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a65646172692f6c61726166696c7465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mjedari/larafilter/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/6288829d26377f5c0613e121db13db8801217305aaad015a72ca804f96bef6c6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d6a65646172692f6c61726166696c7465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572267374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mjedari/larafilter/?branch=master)[![Quality Score](https://camo.githubusercontent.com/be8a9a738556a3a7f38f4915ea39b6d908d9bb28eff0115ec7f47a708279bf6d/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f6d6a65646172692f6c61726166696c7465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/mjedari/larafilter)[![PHP Tests](https://github.com/mjedari/larafilter/workflows/PHP%20Tests/badge.svg)](https://github.com/mjedari/larafilter/workflows/PHP%20Tests/badge.svg)[![PHP 8 Tests](https://github.com/mjedari/larafilter/workflows/PHP%208%20Tests/badge.svg?style=flat)](https://github.com/mjedari/larafilter/workflows/PHP%208%20Tests/badge.svg?style=flat)[![Total Downloads](https://camo.githubusercontent.com/3533bc3a9a17dd51e5a27fd73adbdc63452dd5d30f6a8dbef1ac42667d8581f9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d6a65646172692f6c61726166696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/mjedari/larafilter)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.

Quick start
===========

[](#quick-start)

### Create a filter

[](#create-a-filter)

```
php artisan make:filter country
```

### Implement your filter logic

[](#implement-your-filter-logic)

In the filter class which is created, implement your login in the `apply()` method. In order to get query value just use `$this->value`. We retrieved it for you from your request.

```
...

public function apply(Builder $builder)
{
    return $builder->where('country', $this->value);
}

...
```

### Register filter class for model

[](#register-filter-class-for-model)

Before registering you should use `Filterable` trait in your model.

```
use Filterable;
...

...

protected static $filters = [
    Country::class,
];
```

### Use it!

[](#use-it)

```
// All registered filtered are available through this method:

User::filter()->get();

// Only Specific registered filter is available and executable:

User::filterThrough([Country::class])->get();
```

---

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

[](#installation)

You can install the package via composer:

```
composer require mjedari/larafilter
```

Then you can publish config file:

```
php artisan vendor:publish --provider "Mjedari\Larafilter\LarafilterServiceProvider"
```

Usage
=====

[](#usage)

Initiation
----------

[](#initiation)

Its simple.First create a filter by this command:

```
php artisan make:filter filter-name"
```

Command will create a class under the default directory `App\Filters` :

```
namespace App\Filters;

use Illuminate\Database\Eloquent\Builder;
use Mjedari\Larafilter\Filters\FilterContract;

class Active extends FilterContract
{

   public function apply(Builder $builder)
   {
       // TODO: Implement apply() method.
   }

   public function options()
   {
       // TODO: Implement options() method.
   }

   /*
   * Set rules on the query string
   */
   public function rules()
   {
       return [
           //
       ];
   }

}
```

Your filter logic would be implemented in the `apply()` method:

```
public function apply(Builder $builder)
{
    return $builder->where('avtive', $this->value);
}
```

The important thing is that you have access query string value by `$this->value` in your filter class.

Using
-----

[](#using)

For Which model you want to filter you should add `Filterable` trait in it.

```
class User extends Authenticatable
{
    use Filterable;
    .
    .
    .

```

Then add related filters that you created. It should be static property:

```
use App\Filters\Active;
use App\Filters\City;

class User extends Authenticatable
{
    use Filterable;

    protected static $filters = [
        Active::class,
        City::class
    ];

    .
    .
    .
```

Every thing is ready. just use it in your queries:

```
User::filter()->get();
```

if you want to specify some filter you can pass them thought this method:

```
User::filterThrough([City::class])->get();
```

It's good to mention that this package works with query string. Ex:

```
Route::get('/?country=germany', function() {
    return User->filter()->get();
});
```

So you should pass params through the url. The default query name is filter class name. Of course you can change the filters query name by:

```
class CountryFilter extends FilterContract
{
    public static $queryName = 'country';
    .
    .
    .
```

Also, you can set rules on your query string parameters:

```
class Active extends FilterContract
{

    public function rules()
    {
        return [
            'required',
            Rule::in(['true', 'false']),
        ];
    }
```

More than that sometimes we would like cast query string value. So:

```
class Active extends FilterContract
{

    protected $cast = 'boolean';

    public function rules()
    {
        return [
            //
        ];
    }
```

### Testing

[](#testing)

```
composer test
```

### 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)

- [Mahdi Jedari](https://github.com/mjedari)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~186 days

Total

3

Last Release

1594d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/455b4467ff09733bf4229d59580ef9e6b4a350a30b414ec3c8a97db555083a1b?d=identicon)[mjedari](/maintainers/mjedari)

---

Top Contributors

[![mjedari](https://avatars.githubusercontent.com/u/13734930?v=4)](https://github.com/mjedari "mjedari (17 commits)")

---

Tags

filterlaravelquery-stringquery-filterlaravel filtermjedarilarafilter

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mjedari-larafilter/health.svg)

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

###  Alternatives

[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[liqrgv/query-filter-laravel

Query filter shortcut for controller

102.0k](/packages/liqrgv-query-filter-laravel)

PHPackages © 2026

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