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

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

mcgo/laravel-query
==================

Query eloquent models with custom builders and transformers

1.0.4(4mo ago)0478↓33.3%MITPHPCI failing

Since Oct 24Pushed 4mo agoCompare

[ Source](https://github.com/McGo/laravel-query)[ Packagist](https://packagist.org/packages/mcgo/laravel-query)[ Docs](https://mcgo.dev/packages/laravel-query)[ RSS](/packages/mcgo-laravel-query/feed)WikiDiscussions v1 Synced 1mo ago

READMEChangelog (5)Dependencies (2)Versions (7)Used By (0)

laravel-query
=============

[](#laravel-query)

Filter Eloquent queries based on incoming **HTTP request** parameters — clean, extensible, and framework-native.

> **In short:** Build clean, testable Eloquent queries from request parameters like `?status=active&created_from=2025-01-01&sort=-created_at` — without messy if-else logic in your controllers.

---

Table of Contents
-----------------

[](#table-of-contents)

- [Features](#features)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Extension Points](#extension-points)
- [License](#license)
- [Credits](#credits)

---

Features
--------

[](#features)

- 🧩 **Declarative filters** for Parameter Bags from requests, collection, array.
- 🧰 **Extensible operators**: Build your own query builders with the shipped traits
- 🧽 **Clean controllers**: Move query logic out of controllers
- 🔎 **Optional sorting, limiting and skipping** via custom parameters
- 🛳️ **Custom shipping**: use your own transformer logic to get data as you wish (batteries included).
- 📦 **Framework-native**: works directly on Eloquent Model instances

---

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

[](#installation)

```
composer require mcgo/laravel-query
```

---

Quick Start
-----------

[](#quick-start)

Example: Filtering unfinished `Order` records based on request parameters. You can call the controller with a parameter '?unfinished' to get all unfinished orders.

### Build your QueryBuilder:

[](#build-your-querybuilder)

```
class OrderQueryBuilder extends \McGo\Query\Contracts\AQueryBuilder
{
    use \McGo\Query\Traits\Builder\HasNullFilter;

    // Add filter for unfinished order
    public function filter(): AQueryBuilder {
        // This adds a query ->whereNull('finished_at') if the request has a parameter 'unfinished'
        $this->addNullFilter('finished_at', 'unfinished');
        return $this;
    }

}
```

### Use it in your Controller:

[](#use-it-in-your-controller)

```
use App\Models\Order;
use App\QueryBuilder\OrderQueryBuilder;
use App\Resources\OrderResourceCollection;
use Illuminate\Http\Request;
use McGo\Query\Query;
use McGo\Query\Transformers\JSONResourceCollectionTransformer;

class OrderIndexController
{
    public function __invoke(Request $request)
    {
        return Query::theModel(Order::class)
            ->withBuilder(OrderQueryBuilder::class)
            ->forRequest($request)
            ->to(new JSONResourceCollectionTransformer(OrderResourceCollection::class))
            ->run();
    }
}
```

---

Extension Points
----------------

[](#extension-points)

- Build custom Query Builders for your models
- Build custom Transformers to transform the eloquent collection to your desired format

---

License
-------

[](#license)

[MIT](./LICENSE)

---

Credits
-------

[](#credits)

- Author &amp; Maintainer: [McGo](https://github.com/McGo)
- Purpose: Provide a clean, declarative approach to filtering Eloquent queries based on request parameters.

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance74

Regular maintenance activity

Popularity15

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity39

Early-stage or recently created project

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

Total

6

Last Release

140d ago

### Community

Maintainers

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

---

Top Contributors

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

### Embed Badge

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

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

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11320.2M21](/packages/anourvalar-eloquent-serialize)[overtrue/laravel-versionable

Make Laravel model versionable.

585308.0k5](/packages/overtrue-laravel-versionable)[abbasudo/laravel-purity

elegant way to add filter and sort in laravel

514330.5k1](/packages/abbasudo-laravel-purity)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135192.6k5](/packages/statamic-rad-pack-runway)[dragon-code/laravel-deploy-operations

Performing any actions during the deployment process

240173.5k2](/packages/dragon-code-laravel-deploy-operations)[stayallive/laravel-eloquent-observable

Register Eloquent model event listeners just-in-time directly from the model.

2928.9k7](/packages/stayallive-laravel-eloquent-observable)

PHPackages © 2026

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