PHPackages                             mustorze/mustafilter - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mustorze/mustafilter

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mustorze/mustafilter
====================

A Filter for Laravel

1.6.0(1y ago)10319MITPHPPHP ^8.0

Since Jul 6Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mustorze/MustAFilter)[ Packagist](https://packagist.org/packages/mustorze/mustafilter)[ RSS](/packages/mustorze-mustafilter/feed)WikiDiscussions master Synced today

READMEChangelog (10)Dependencies (2)Versions (18)Used By (0)

Must a Filter
=============

[](#must-a-filter)

A simple management filters for Laravel, use into REST and GraphQL

### Prerequisites

[](#prerequisites)

- To run this project, you must have `php >= 7.1`, `laravel\framework >= 5.4.*` and `webonyx/graphql-php ~0.10.0`
- Yes it`s made for Laravel

### Step 1

[](#step-1)

- Include in yours `composer.json` in the requirements these `"mustorze/mustafilter": "1.0"` then run `composer update`
- Or just run `composer require mustorze/mustafilter`

### Step 2

[](#step-2)

- Add `Mustorze\MustAFilter\Traits\Filterable` trait to models you want to filter.

### Step 3

[](#step-3)

- Extend your Filter class from from `Mustorze\MustAFilter\Contracts\Filter` Abstract one
- This is a example filter for a `user` model

```
class UserFilter extends Mustorze\MustAFilter\Contracts\Filter
{
    /**
     * Declare here all the filters that can be used in the model
     */
    protected $filters = [
        'email'
    ];

    /**
    * If you're using GraphQL declare here the type and description of the filter
    * Available Types: 'string', 'boolean', 'integer', 'float', 'list-of-boolean', 'list-of-integer', 'list-of-float', 'list-of-string'
    */
    protected $filtersSpec = [
        'email' => [
            'type' => 'string', // You can specify any type available in GraphQL from the list above
            'description' => 'like filter by user email'
      ]
    ];

    /**
     * The filter will be applied to the constructor with the name declared in $filters
     *
     * @param $value
     * @return mixed
     */
    protected function email($value)
    {
        return $this->builder->where('email', 'LIKE', "%$value%");
    }
}
```

##### All ready

[](#all-ready)

### How to use

[](#how-to-use)

GraphQL
-------

[](#graphql)

This is a default query in GraphQL

```
class UsersQuery extends Query
{
    /**
    * To makes things easy, i've create a const for the filter i will use in this query
    */
    const FILTER = UserFilter::class; // it's the same class that was created before

    /**
    * Query default configuration
    */
    protected $attributes = [
        'name' => 'Admin users query',
        'description' => 'The query pagination of users'
    ];

    /**
    * Query default type
    */
    public function type()
    {
        return GraphQL::paginate('user');
    }

    /**
     * Here is the first place we can modify, in this moment we need to use a `getFilterArgs` method to Get all the
     * filters we created in the Filter.
     * When you use `Filterable` trait, your model own the `getFilterArgs` automatic.
     * 1st param - The filter, you can create a infinites filters to use in your queries
     * 2nd param - The defaults args, pass in array the default args can you always do to the query
     */
    public function args()
    {
        return User::getFilterArgs($this::FILTER, [
            'page' => [
                'name' => 'page',
                'type' => Type::nonNull(Type::int()),
                'description' => 'The page'
            ],
            'limit' => [
                'name' => 'limit',
                'type' => Type::nonNull(Type::int()),
                'description' => 'The limit'
            ]
        ]);
    }

    /**
    * The default resolve
    */
    public function resolve($root, $args, SelectFields $fields, ResolveInfo $info)
    {
        $select = $fields->getSelect();
        $with = $fields->getRelations();

        /**
        * The second place to modify we found here, we need to pass filter scope to the builder, and then he will
        * validate and apply your filters in the query.
        * 1st param - The filter, you can create a infinites filters to use in your queries
        * 2rd param - There we pass the args of query, it`s simple, we need to get the passed values from query to
        * makes things working.
        */
        return User::select($select)
            ->with($with)
            ->filter($this::FILTER, $args) // The filter
            ->paginate($args['limit'], $select, 'page', $args['page']);
    }
}
```

If your followed all the steps well, you can easily test your query passing the filter your want in args of your query

#### Now we know how to use in GraphQL

[](#now-we-know-how-to-use-in-graphql)

### REST

[](#rest)

In REST we usually make a query with some arguments we needs to use and we return the results of this query for the requesters

Example:

```
public function fetchAllUsers()
{
    return User::where('status', 1) // a default query settings
        ->get();
}
```

With the Filter, you need to add the Filter scope to the constructor. the Filter Scope automatically detects the arguments in the request and apply in the query

```
public function fetchAllUsers()
{
    return User::where('status', 1) // a default query settings
        ->filter(UserFilter::class) // do not need to pass the further parameters
        ->get();
}
```

Now if this request is a POST or GET, and have a `email` param in the request, the `email` filter its applied to the builder `localhost/users/?email=example.com`The filter we was created are applying a `where like` in query, all the results than have `example.com` in email column will be returned

###  Health Score

38

—

LowBetter than 85% of packages

Maintenance38

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity76

Established project with proven stability

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

Recently: every ~372 days

Total

17

Last Release

533d ago

PHP version history (2 changes)1.1.0PHP &gt;=7.1

1.4.1PHP ^8.0

### Community

Maintainers

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

### Embed Badge

![Health badge](/badges/mustorze-mustafilter/health.svg)

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

###  Alternatives

[wireui/wireui

TallStack components

1.8k1.3M16](/packages/wireui-wireui)[livewire/volt

An elegantly crafted functional API for Laravel Livewire.

4195.3M84](/packages/livewire-volt)[ramonrietdijk/livewire-tables

Dynamic tables for models with Laravel Livewire

21147.4k](/packages/ramonrietdijk-livewire-tables)

PHPackages © 2026

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