PHPackages                             myerscode/laravel-query-strategies - 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. myerscode/laravel-query-strategies

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

myerscode/laravel-query-strategies
==================================

A package for applying filters, ordering, eager loads, result limiting and pagination to Eloquent queries

13.0.0(1mo ago)462MITPHPPHP ^8.5CI passing

Since Sep 1Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/myerscode/laravel-query-strategies)[ Packagist](https://packagist.org/packages/myerscode/laravel-query-strategies)[ Docs](https://github.com/myerscode/laravel-query-strategies)[ RSS](/packages/myerscode-laravel-query-strategies/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (13)Versions (13)Used By (0)

Laravel Query Strategies
========================

[](#laravel-query-strategies)

Build safe, flexible API endpoints by turning URL query parameters into Eloquent queries. Define a strategy that controls exactly which filters, sorts, fields, and relationships your API consumers can use.

[![Latest Stable Version](https://camo.githubusercontent.com/f428a5ac1a095708440d49a761822bc9365254f28f3b24fc77c4d5173818b33b/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d71756572792d737472617465676965732f762f737461626c65)](https://packagist.org/packages/myerscode/laravel-query-strategies)[![Total Downloads](https://camo.githubusercontent.com/23652757590ff0f819ed65db5f5fc5dc0577b15a450ef859ef2e878cc0e51067/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d71756572792d737472617465676965732f646f776e6c6f616473)](https://packagist.org/packages/myerscode/laravel-query-strategies)[![PHP Version Require](https://camo.githubusercontent.com/79d86c899a602c1304b6f13ef23db62c160a75dc6316e2e9cfd55d9fe3fe7993/687474703a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d71756572792d737472617465676965732f726571756972652f706870)](https://packagist.org/packages/myerscode/laravel-query-strategies)[![License](https://camo.githubusercontent.com/7b8d0f07dd7bdc4b4e2f2040c3fc395bccdd311fab0268334b176295c52c210a/68747470733a2f2f706f7365722e707567782e6f72672f6d79657273636f64652f6c61726176656c2d71756572792d737472617465676965732f6c6963656e7365)](https://github.com/myerscode/laravel-query-strategies/blob/main/LICENSE)[![Tests](https://github.com/myerscode/laravel-query-strategies/actions/workflows/tests.yml/badge.svg?branch=main)](https://github.com/myerscode/laravel-query-strategies/actions/workflows/tests.yml)[![codecov](https://camo.githubusercontent.com/d6807d211e12cba274cec56f9767642039b4b5804d94ff9b2ab1724c9f5cc791/68747470733a2f2f636f6465636f762e696f2f67682f6d79657273636f64652f6c61726176656c2d71756572792d737472617465676965732f67726170682f62616467652e737667)](https://codecov.io/gh/myerscode/laravel-query-strategies)

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

[](#requirements)

- PHP ^8.5
- Laravel ^13.0

Quick Example
-------------

[](#quick-example)

Given a `ProductStrategy` that defines which parameters are allowed:

```
class ProductStrategy extends Strategy
{
    protected array $canOrderBy = ['name', 'price', 'created_at'];
    protected array $canWith = ['category', 'reviews'];
    protected array $allowedFields = ['id', 'name', 'price', 'category_id'];
    protected array $allowedAppends = ['discount_price'];

    protected array $config = [
        'name'     => ['filter' => ContainsClause::class],
        'price'    => ['column' => 'unit_price'],
        'category' => ['column' => 'category_id', 'explode' => true],
    ];
}
```

Your API consumers can now query like this:

```
GET /products?name=laptop&price=500&category=1,2,3&order=price&sort=desc&limit=10&with=reviews&fields=id,name,price&append=discount_price

```

And in your controller:

```
use function Myerscode\Laravel\QueryStrategies\filter;

public function index()
{
    return filter(Product::class)->with(ProductStrategy::class)->apply();
}
```

That single line handles filtering, sorting, field selection, eager loading, accessor appending, limiting, and pagination — all controlled by the strategy.

Why Use This?
-------------

[](#why-use-this)

- **Safe by default** — only parameters defined in your strategy are applied. Unknown parameters are ignored (or rejected in strict mode).
- **Column obfuscation** — map public parameter names to real database columns so your schema stays private.
- **Flexible clauses** — 17 built-in filter clauses (equals, contains, between, greater than, etc.) with operator overrides via URL.
- **Relationship support** — filter through relationships with dot notation, sort by relationship columns, and control eager loading.
- **Composable** — chain individual methods (`filter()`, `order()`, `fields()`, etc.) or call `apply()` to run everything at once.

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

[](#installation)

```
composer require myerscode/laravel-query-strategies
```

The package auto-discovers its service provider. No manual registration needed.

Documentation
-------------

[](#documentation)

- [Usage](docs/usage.md) — Getting started, creating filters, query parameter syntax, and pagination
- [Strategies](docs/strategies.md) — Defining strategies, parameter options, ordering, limiting, eager loads, and default filters
- [Clauses](docs/clauses.md) — Built-in clauses, scope and trashed filtering, callbacks, and custom clauses
- [Transmutes](docs/transmutes.md) — Transforming values before filtering
- [Configuration](docs/configuration.md) — Customising parameter names and strict mode

License
-------

[](#license)

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

###  Health Score

54

—

FairBetter than 97% of packages

Maintenance91

Actively maintained with recent releases

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity86

Battle-tested with a long release history

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

Recently: every ~573 days

Total

8

Last Release

45d ago

Major Versions

1.0.0 → 6.0.02019-12-15

6.0.0 → 7.0.02020-07-31

7.0.0 → 8.0.02021-01-07

8.0.0 → 10.0.02023-05-12

10.0.0 → 13.0.02026-03-28

PHP version history (5 changes)0.0.1PHP ^7.1

7.0.0PHP ^7.4

8.0.0PHP ^7.3|^8.0

10.0.0PHP ^8.1

13.0.0PHP ^8.5

### Community

Maintainers

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

---

Top Contributors

[![oniice](https://avatars.githubusercontent.com/u/2676321?v=4)](https://github.com/oniice "oniice (85 commits)")

---

Tags

eloquentfilterlaravellaravel-query-strategiesorderingpaginationqueryrequestlaravelpaginationeloquentqueryfilterorderinglimiting

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/myerscode-laravel-query-strategies/health.svg)

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

###  Alternatives

[tucker-eric/eloquentfilter

An Eloquent way to filter Eloquent Models

1.8k4.8M26](/packages/tucker-eric-eloquentfilter)[mehdi-fathi/eloquent-filter

Eloquent Filter adds custom filters automatically to your Eloquent Models in Laravel.It's easy to use and fully dynamic, just with sending the Query Strings to it.

450191.6k1](/packages/mehdi-fathi-eloquent-filter)[jerome/filterable

Streamline dynamic Eloquent query filtering with seamless API request integration and advanced caching strategies.

19226.1k](/packages/jerome-filterable)[omalizadeh/laravel-query-filter

A laravel package for resource filtering via request query string

163.0k](/packages/omalizadeh-laravel-query-filter)[aldemeery/sieve

A simple, clean and elegant way to filter Eloquent models.

1396.3k](/packages/aldemeery-sieve)

PHPackages © 2026

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