PHPackages                             ayman-els/laravel-filter-package - 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. ayman-els/laravel-filter-package

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

ayman-els/laravel-filter-package
================================

A Laravel package with a custom filtering trait

v1.0.0(2y ago)0100MITPHP

Since Aug 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AymanElsAhmed/laravel-filter)[ Packagist](https://packagist.org/packages/ayman-els/laravel-filter-package)[ RSS](/packages/ayman-els-laravel-filter-package/feed)WikiDiscussions main Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

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

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

#### Filter your queries based on url query string parameters like a breeze.

[](#filter-your-queries-based-on-url-query-string-parameters-like-a-breeze)

*Compatible with Laravel **5.x** **6.x** **7.x** **8.x** **9.x** **10.x***.

Table of Content
----------------

[](#table-of-content)

- [Describing the Problem](#Describing-the-Problem)
- [Usage](#Usage)
    - [Installation](#Usage)

Describing the Problem
----------------------

[](#describing-the-problem)

You have probably faced the situation where you needed to filter your query based on given parameters in url query-string and after developing the logics, You've had such a code:

```
$users = User::latest();

if(request('username')) {
    $users->where('username', request('username'));
}

if(request('age')) {
    $users->where('age', '>', request('age'));
}

if(request('email')) {
    $users->where('email', request('email'));
}

return $users->get();
```

This works, But it's not a good practice.

When the number of parameters starts to grow, The number of these kind of `if` statements also grows and your code gets huge and hard to maintain.

Also it's against the Open/Closed principal of SOLID principles, Because when you have a new parameter, You need to get into your existing code and add a new logic (which may breaks the existing implementations).

So we have to design a way to make our filters logics separated from each other and apply them into the final query, which is the whole idea behind this package.

Usage
-----

[](#usage)

1. First you need to install the package:

`$ composer require ayman-els/laravel-filter-package`

2. Then you should `use` the `Filter` trait in your model, And define `$filterCols, $filterDates, $filterSearchCols, $filterColsChilds` property.

```
use AymanEls\LaravelFilterPackage\Traits\Filter;

class Product extends Model
{
    use Filter;

    public static $filterCols = ['category_id', 'department_id', 'user_id'];
    public static $filterDates = ['from' => 'created_at', 'to' => 'created_at'];
    public static $filterSearchCols = ['name_en', 'name_ar', 'description'];
    public static $filterColsChilds = ['currency' => 'department'];

    ...
}
```

3. You need to use `filter()` method in your eloquent query. For example:

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

assume our query is something like this:

```
?search=field&from=2023-01-01&to=2023-01-02&category_id=1&department_id=1&user_id=1&currency=1
```

###  Health Score

22

—

LowBetter than 21% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Unknown

Total

1

Last Release

1052d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31375408?v=4)[Ayman Elsayed](/maintainers/AymanElsAhmed)[@AymanElsAhmed](https://github.com/AymanElsAhmed)

---

Top Contributors

[![AymanElsAhmed](https://avatars.githubusercontent.com/u/31375408?v=4)](https://github.com/AymanElsAhmed "AymanElsAhmed (6 commits)")

---

Tags

searchlaravelfilter

### Embed Badge

![Health badge](/badges/ayman-els-laravel-filter-package/health.svg)

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

###  Alternatives

[outl1ne/nova-input-filter

An input filter for Laravel Nova

241.0M](/packages/outl1ne-nova-input-filter)[optimistdigital/nova-input-filter

An input filter for Laravel Nova

24576.2k2](/packages/optimistdigital-nova-input-filter)[remoblaser/search

A simple to implement Search for your Application

101.5k](/packages/remoblaser-search)

PHPackages © 2026

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