PHPackages                             tijanidevit/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. [Database &amp; ORM](/categories/database)
4. /
5. tijanidevit/query-filter

ActivePackage[Database &amp; ORM](/categories/database)

tijanidevit/query-filter
========================

A simple, expressive, and powerful Laravel package that provides dynamic Eloquent models filters with clean syntax. It helps build reusable, maintainable, and readable query logic in Laravel apps.

1.0.0(7mo ago)3179MITPHP

Since May 5Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/tijanidevit/laravel-query-filter)[ Packagist](https://packagist.org/packages/tijanidevit/query-filter)[ RSS](/packages/tijanidevit-query-filter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

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

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

A simple, expressive, and powerful Laravel package that provides dynamic Eloquent model filters with clean syntax. It helps you build reusable, maintainable, and readable query logic in Laravel applications.

[![Latest Version on Packagist](https://camo.githubusercontent.com/1be89a25cd237dd5720dad829f45edca52bcbe46e8ba459044323a311e294760/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f74696a616e6964657669742f71756572792d66696c7465722e737667)](https://packagist.org/packages/tijanidevit/query-filter)[![Downloads](https://camo.githubusercontent.com/00d1e81537cf942fb75956659192fb9da19324f8d4e8befb07d6628223892578/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f74696a616e6964657669742f71756572792d66696c7465722e737667)](https://packagist.org/packages/tijanidevit/query-filter)[![License](https://camo.githubusercontent.com/dd4bb05e2be36580d27d2429154db75183f4d704fa3ea735ade96f223e310835/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f74696a616e6964657669742f71756572792d66696c7465722e737667)](LICENSE)

---

🎯 Why Use This Package?
-----------------------

[](#-why-use-this-package)

In many Laravel applications—especially admin dashboards, reporting systems, and search pipelines—developers often repeat the same verbose filtering logic in controllers:

```
$query = User::query();

if (request()->filled('name')) {
    $query->where('name', request('name'));
}

if (request()->filled('status')) {
    $query->where('status', request('status'));
}

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

**With Query Filter, you can simplify this down to a single, beautifully readable chain:**

```
User::query()
    ->filterBy([
        'name' => request('name'),
        'status' => request('status'),
    ])
    ->get();
```

*It safely ignores empty parameters automatically, so you never write an `if (request()->filled(...))` block again.*

---

🚀 Installation
--------------

[](#-installation)

Install the package via Composer:

```
composer require tijanidevit/query-filter
```

*(Optional)* The package supports Auto-Discovery. If you are using an older version of Laravel (pre-5.5), manually register the provider in `config/app.php`:

```
'providers' => [
    Tijanidevit\QueryFilter\Providers\FilterProvider::class,
]
```

### Applying the Trait

[](#applying-the-trait)

Query Filter utilizes Laravel Scopes. To enable filtering on a model, add the `Filterable` trait:

```
namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Tijanidevit\QueryFilter\Traits\Filterable;

class User extends Model
{
    use Filterable;
}
```

---

⚡ Database Drivers &amp; ILIKE Support
--------------------------------------

[](#-database-drivers--ilike-support)

The package dynamically detects your database connection. If you are using **PostgreSQL**, all `search()`, `searchIn()`, `orSearch()`, and `searchByRelation()` methods will automatically utilize the case-insensitive `ILIKE` operator. For all other SQL databases (MySQL, SQLite), it will default natively to `LIKE`.

---

📚 Available Filters
-------------------

[](#-available-filters)

### `filterBy()`

[](#filterby)

Filter by a single column or multiple columns using exact matches.

```
// Single column matching
User::query()->filterBy('status', 'active')->get();

// Multiple columns exact matching
User::query()->filterBy([
    'name' => 'Jane',
    'status' => ['active', 'pending'], // Safely wraps to WhereIn natively!
])->get();

// Secure Null checks automatically
User::query()->filterBy([
    'email_verified_at' => ['null' => true],
])->get();
```

### `filterByRelation()`

[](#filterbyrelation)

Filter directly using nested related models cleanly without verbose `whereHas` queries.

```
Post::query()->filterByRelation([
    'author' => [
        'status' => 'active',
        'is_banned' => false
    ]
])->get();
```

### `filterWhereIn()`

[](#filterwherein)

Flexible `WHERE IN` filtering parsing arrays and strings automatically.

```
// Standard Array
User::query()->filterWhereIn('status', ['active', 'pending'])->get();

// Comma-delimited strings (Ideal for external API requests)
User::query()->filterWhereIn('status', 'active,pending')->get();

// Variadic arguments
User::query()->filterWhereIn('status', 'active', 'pending')->get();
```

### `search()`, `searchIn()`, and `orSearch()`

[](#search-searchin-and-orsearch)

Powerful dynamic `LIKE` search abstractions.

```
// AND logic across multiple fields
User::query()->search(['name' => 'John', 'city' => 'Lagos'])->get();

// searchIn(): Grouped OR searching across multiple fields using a single keyword constraint
User::query()->searchIn(['first_name', 'last_name', 'email'], 'john')->get();

// orSearch(): Chained top-level grouped OR blocks gracefully appended to pre-existing searches
Article::query()
    ->search('category', 'technology')
    ->orSearch(['title', 'summary'], 'laravel')
    ->get();
```

### `filterFromRequest()`

[](#filterfromrequest)

Automatically bind constraints directly from incoming HTTP Request objects by mapping input keys to database columns.

```
User::query()->filterFromRequest(request(), [
    'email' => 'login_email',   // Translates to: where email = request('login_email')
    'department_id' => 'dept',
])->get();
```

### `filterByDate()`, `filterByMonth()`, `filterByYear()`, `filterByDateRange()`

[](#filterbydate-filterbymonth-filterbyyear-filterbydaterange)

Timezone-aware date parsing spanning specific bounding frames neatly.

```
// Filter single explicit matching date period ranges
User::query()->filterByDate('2024-01-01')->get();

// Search date boundaries safely ignoring omitted limits
Order::query()->filterByDateRange(request('date_from'), request('date_to'))->get();

// Isolate month timelines seamlessly
Post::query()->filterByMonth([1, 2])->get();
```

### Sorting Helpers

[](#sorting-helpers)

Chainable dynamic chronological sorting bounds.

```
User::query()
    ->sortResultBy(request('sort_column'), request('sort_direction'))
    ->latestBy('last_login')
    ->get();
```

---

💡 Advanced Best Practices
-------------------------

[](#-advanced-best-practices)

Query Filter macros are designed to act composably, linking infinitely together parsing structural queries perfectly.

### The "God Query" Approach

[](#the-god-query-approach)

For complex Admin panels parsing 15 distinct variables simultaneously, combine macros sequentially:

```
$users = User::query()
    ->filterBy([
        'status' => request('status'),
        'email_verified_at' => ['null' => request('missing_email_verification')],
    ])
    ->filterWhereIn([
        'department' => request('departments'), // Array or comma-delimited natively evaluated
    ])
    ->filterByRelation([
        'manager' => [
            'status' => 'active',
        ],
    ])
    ->filterByDateRange(request('from'), request('to'))
    ->searchIn(['name', 'email', 'biography'], request('search_query'))
    ->sortResultBy(request('sort_by', 'created_at'), request('sort_dir', 'desc'))
    ->latestBy('last_login')
    ->get();
```

### Structural Security Recommendations

[](#structural-security-recommendations)

1. **Always validate request inputs** before blindly dumping `request()` into maps.
2. Use arrays or comma-delimited structures intelligently parsed with `filterWhereIn()` bridging dashboard parameters structurally.
3. Funnel heavy endpoint evaluations entirely into `filterFromRequest()` maps for ultra-slim API Controllers.

---

🛠 Requirements
--------------

[](#-requirements)

- Laravel 9, 10, or 11+
- PHP 8.0+

📄 License
---------

[](#-license)

This package is open-sourced software licensed under the MIT license.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance76

Regular maintenance activity

Popularity19

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

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

Every ~24 days

Total

9

Last Release

228d ago

Major Versions

v0.0.8 → 1.0.02025-11-16

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/57565055?v=4)[Mustapha TIJANI](/maintainers/tijanidevit)[@tijanidevit](https://github.com/tijanidevit)

---

Top Contributors

[![tijanidevit](https://avatars.githubusercontent.com/u/57565055?v=4)](https://github.com/tijanidevit "tijanidevit (19 commits)")

### Embed Badge

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

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

###  Alternatives

[jdorn/sql-formatter

a PHP SQL highlighting library

3.9k117.2M118](/packages/jdorn-sql-formatter)[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[jfelder/oracledb

Oracle DB driver for Laravel

11518.4k](/packages/jfelder-oracledb)

PHPackages © 2026

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