PHPackages                             ekramhossain/laravel-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. ekramhossain/laravel-query-filter

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

ekramhossain/laravel-query-filter
=================================

A flexible query filtering package for Laravel with operators, date ranges, relational filters, and sorting.

v1.0.0(yesterday)00MITPHPPHP ^8.1

Since Aug 8Pushed yesterdayCompare

[ Source](https://github.com/ekrambd/laravel-query-filter-package)[ Packagist](https://packagist.org/packages/ekramhossain/laravel-query-filter)[ RSS](/packages/ekramhossain-laravel-query-filter/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (2)Used By (0)

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

[](#laravel-query-filter)

A flexible and lightweight query filtering package for Laravel Eloquent with support for:

- Allowed filters
- String search
- Comparison operators
- Date range filtering
- Relational filtering
- Multiple sorting
- Ascending and descending sorting

Requirements
------------

[](#requirements)

- PHP `^8.1`
- Laravel `9.x`
- Laravel `10.x`
- Laravel `11.x`
- Laravel `12.x`

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

[](#installation)

Install the package via Composer:

```
composer require ekramhossain/laravel-query-filter
```

The package automatically registers its service provider and `Filter` facade.

Configuration
-------------

[](#configuration)

Publish the configuration file:

```
php artisan vendor:publish --tag=query-filter-config
```

This will publish:

```
config/query-filter.php

```

Basic Usage
-----------

[](#basic-usage)

Suppose you have a `Product` model:

```
use App\Models\Product;
use EkramHossain\LaravelQueryFilter\Facades\Filter;

public function index(Request $request)
{
    $products = Filter::query(Product::query())
        ->allowedFilters([
            'name',
            'status',
            'price',
            'created_at',
        ])
        ->allowedSorts([
            'name',
            'price',
            'created_at',
        ])
        ->apply($request)
        ->paginate();

    return response()->json($products);
}
```

Basic Filtering
---------------

[](#basic-filtering)

Request:

```
/api/products?filter[status]=active

```

Equivalent query:

```
WHERE status = 'active'
```

String Filtering
----------------

[](#string-filtering)

String values are automatically treated as a `LIKE` search.

Request:

```
/api/products?filter[name]=phone

```

Equivalent query:

```
WHERE name LIKE '%phone%'
```

Comparison Operators
--------------------

[](#comparison-operators)

The following operators are supported:

OperatorMeaning`eq`Equal`gt`Greater than`gte`Greater than or equal`lt`Less than`lte`Less than or equal### Equal

[](#equal)

```
/api/products?filter[price][eq]=1000

```

### Greater Than

[](#greater-than)

```
/api/products?filter[price][gt]=1000

```

### Greater Than Or Equal

[](#greater-than-or-equal)

```
/api/products?filter[price][gte]=1000

```

### Less Than

[](#less-than)

```
/api/products?filter[price][lt]=1000

```

### Less Than Or Equal

[](#less-than-or-equal)

```
/api/products?filter[price][lte]=1000

```

Date Range Filtering
--------------------

[](#date-range-filtering)

Date range filtering is supported using `from` and `to`.

Example:

```
/api/leaves?filter[issue_date][from]=2026-08-01&filter[issue_date][to]=2026-08-08

```

This produces a query equivalent to:

```
WHERE DATE(issue_date) >= '2026-08-01'
AND DATE(issue_date) allowedFilters([
    'name',
    'category.name',
])
```

Request:

```
/api/products?filter[category.name]=electronics

```

This will use Eloquent's `whereHas()` internally.

For example:

```
Product::query()
    ->whereHas('category', function ($query) {
        $query->where(
            'name',
            'like',
            '%electronics%'
        );
    });
```

Nested relationships are also supported:

```
->allowedFilters([
    'category.parent.name',
])
```

Sorting
-------

[](#sorting)

Define allowed sorting columns:

```
->allowedSorts([
    'name',
    'price',
    'created_at',
])
```

### Ascending

[](#ascending)

```
/api/products?sort=price

```

Equivalent to:

```
ORDER BY price ASC
```

### Descending

[](#descending)

Prefix the column with `-`:

```
/api/products?sort=-price

```

Equivalent to:

```
ORDER BY price DESC
```

Multiple Sorting
----------------

[](#multiple-sorting)

Multiple sorting columns can be passed using commas:

```
/api/products?sort=-created_at,price

```

Equivalent to:

```
ORDER BY created_at DESC, price ASC
```

Multiple Filters
----------------

[](#multiple-filters)

Multiple filters can be combined:

```
/api/products?filter[status]=active&filter[price][gte]=500&filter[price][lte]=2000

```

Security
--------

[](#security)

Only fields explicitly defined through `allowedFilters()` can be filtered.

```
->allowedFilters([
    'name',
    'status',
    'price',
])
```

Only fields defined through `allowedSorts()` can be sorted.

```
->allowedSorts([
    'name',
    'price',
])
```

Unknown filters and sorting fields are ignored.

This prevents users from arbitrarily controlling which database columns are queried.

Complete Example
----------------

[](#complete-example)

```
use App\Models\Product;
use Illuminate\Http\Request;
use EkramHossain\LaravelQueryFilter\Facades\Filter;

public function index(Request $request)
{
    $products = Filter::query(Product::query())
        ->allowedFilters([
            'name',
            'status',
            'price',
            'manufacture_date',
            'category.name',
        ])
        ->allowedSorts([
            'name',
            'price',
            'manufacture_date',
            'created_at',
        ])
        ->apply($request)
        ->paginate(20);

    return response()->json([
        'success' => true,
        'data' => $products,
    ]);
}
```

Example request:

```
/api/products?filter[status]=active&filter[price][gte]=500&filter[manufacture_date][from]=2026-01-01&filter[manufacture_date][to]=2026-01-31&filter[category.name]=electronics&sort=-created_at,price

```

Supported Features
------------------

[](#supported-features)

FeatureSupportedBasic filtering✅String LIKE search✅`eq`✅`gt`✅`gte`✅`lt`✅`lte`✅Date range✅Relationship filtering✅Nested relationship filtering✅Ascending sorting✅Descending sorting✅Multiple sorting✅Allowed filters✅Allowed sorts✅License
-------

[](#license)

This package is open-sourced software licensed under the [MIT License](LICENSE).

Author
------

[](#author)

**Md. Ekram Hossain**

GitHub: `https://github.com/ekrambd/`

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity42

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

1d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/55123967?v=4)[ekrambd](/maintainers/ekrambd)[@ekrambd](https://github.com/ekrambd)

---

Top Contributors

[![ekrambd](https://avatars.githubusercontent.com/u/55123967?v=4)](https://github.com/ekrambd "ekrambd (1 commits)")

---

Tags

laraveleloquentqueryfiltersortingdate-rangequery-filter

### Embed Badge

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

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

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3345.4M354](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58190.1k19](/packages/api-platform-laravel)[forjedio/inertia-table

Backend-driven dynamic tables for Laravel + Inertia.js

272.0k](/packages/forjedio-inertia-table)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45844.8k1](/packages/pressbooks-pressbooks)

PHPackages © 2026

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