PHPackages                             kayckmatias/z-filters - 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. kayckmatias/z-filters

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

kayckmatias/z-filters
=====================

a simple way to dynamically filter your Laravel models

0.0.1(2y ago)82543MITPHPPHP ^8.0

Since Sep 4Pushed 2y ago1 watchersCompare

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

READMEChangelog (1)DependenciesVersions (2)Used By (0)

zFilters
========

[](#zfilters)

##### a simple package to filter your Laravel models without repetitive loops or various if-else

[](#a-simple-package-to-filter-your-laravel-models-without-repetitive-loops-or-various-if-else)

[![Version](https://camo.githubusercontent.com/2e1a222ce6cc95b3700e77b7326f9b335819f19b2b3e72c7ca4ffc3eb94383ad/687474703a2f2f706f7365722e707567782e6f72672f6b6179636b6d61746961732f7a2d66696c746572732f76657273696f6e)](https://packagist.org/packages/kayckmatias/z-filters)[![Total Downloads](https://camo.githubusercontent.com/1c298af33e356a704226dde9bca23b944cd6c7dd79d990364606cfe64b2f6967/687474703a2f2f706f7365722e707567782e6f72672f6b6179636b6d61746961732f7a2d66696c746572732f646f776e6c6f616473)](https://packagist.org/packages/kayckmatias/z-filters)[![License](https://camo.githubusercontent.com/f5883023f2e216f993e7ec37a66e55170b9e8ec6e3bd68a610ebe5f568be4a10/687474703a2f2f706f7365722e707567782e6f72672f6b6179636b6d61746961732f7a2d66696c746572732f6c6963656e7365)](https://packagist.org/packages/kayckmatias/z-filters)

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

[](#installation)

You can install the package via composer:

```
composer require kayckmatias/z-filters
```

Usage
-----

[](#usage)

You just need two things: make a new filter and create a scope in your model to point filter.

To make a new Filter:

```
php artisan make:zfilter NameFilter
```

Example:

[![Example new Filter Image](https://camo.githubusercontent.com/a59594f813f06635c1a1130d3cfbc67408a2298db3d20de00b1b5e883858284b/68747470733a2f2f692e696d6775722e636f6d2f4136646d7131512e706e67)](https://camo.githubusercontent.com/a59594f813f06635c1a1130d3cfbc67408a2298db3d20de00b1b5e883858284b/68747470733a2f2f692e696d6775722e636f6d2f4136646d7131512e706e67)

and configure your filter options according to your preference ([read here](#configure))

Now, is need make a scope in your model, example:

```
public function scopeFilterBy(Builder $query, array $filters)
{
    $filter = new UsersFilter($query, $filters);

    return $filter->apply();
}
```

Configure
---------

[](#configure)

zFilters supports three filters type: simple, relation and complex.

#### Simple Filters:

[](#simple-filters)

Simple Filter is a whereIn condition, when you make a simple filter you is saying.

```
'custom_name' => 'column to verify set whereIn'
```

Let's assume that your user table has the column "department\_id", to make a simple filter you just need to reference how the name of the filter option will be, let's call it "departments" and the column, which would be "department\_id"

```
'departaments' => 'departament_id'
```

Now the array of values or single value you send in $filters\['departments'\] will be filtered in whereIn condition on the simple filter

#### Relation Filters:

[](#relation-filters)

Relation Filter is a whereIn condition in a relation, when you make a relation filter you is saying.

```
'custom_name' => ['relation' => 'column to verify set whereIn']
```

Let's assume that your User model has the relation with department (departments()), to create a relationship filter where we must get all the users that the department belongs to manager 1 or 2 we can do this:

```
'departments_manager' => ['departments' => 'manager_id']
```

Now the array of values or single value you send in $filters\['departments\_manager'\] will be filtered in whereIn condition in departments relation on manager\_id column.

#### Complex Filters

[](#complex-filters)

The complex filter can deal with more specific conditions, it accepts a callback function and you can filter however you want, let's go to another example. Assuming your same user table has a name column and a summary column and you expect to do a complex search for both conditions by value, one way to do it would be:

```
'search' => function ($q, $filterValue) {
    $q->where(function ($q) use ($filterValue) {
        $q->where('name', 'LIKE', "%" . $filterValue . "%");
        $q->orWhere('summary', 'LIKE', "%" . $filterValue . "%");
    });
}
```

The complex filter option named 'search' will execute the function, the value of $q will be the query builder being formed and the second parameter, $filterValue will be automatically implemented to what is sent in $filters\['search'\], as it is a callback function you can work on it too, manipulate the values sent, as if it were inside the query builder itself.

License
-------

[](#license)

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

Made with ♥ by Kayck Matias

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity19

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

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

Unknown

Total

1

Last Release

982d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8c208ca332908e1c58347b7c3fbe455a63015b5826f1fcfd6c95e3c090ada1a2?d=identicon)[kayckmatias](/maintainers/kayckmatias)

---

Top Contributors

[![KayckMatias](https://avatars.githubusercontent.com/u/48569093?v=4)](https://github.com/KayckMatias "KayckMatias (22 commits)")[![linoaugusto](https://avatars.githubusercontent.com/u/57725524?v=4)](https://github.com/linoaugusto "linoaugusto (1 commits)")

### Embed Badge

![Health badge](/badges/kayckmatias-z-filters/health.svg)

```
[![Health](https://phpackages.com/badges/kayckmatias-z-filters/health.svg)](https://phpackages.com/packages/kayckmatias-z-filters)
```

###  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)[outl1ne/nova-multiselect-filter

Multiselect filter for Laravel Nova.

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

a general purpose text search engine written entirely in PHP 5

39921.0k35](/packages/handcraftedinthealps-zendsearch)

PHPackages © 2026

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