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

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

arielmejiadev/laravel-query-class
=================================

it creates query classes to handle easily requests with multiple filters, sorts and includes.

1.0.1(4y ago)37MITPHPPHP ^7.4|^8.0

Since Jul 13Pushed 3y ago1 watchersCompare

[ Source](https://github.com/ArielMejiaDev/laravel-query-class)[ Packagist](https://packagist.org/packages/arielmejiadev/laravel-query-class)[ Docs](https://github.com/arielmejiadev/laravel-query-class)[ RSS](/packages/arielmejiadev-laravel-query-class/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (2)Dependencies (3)Versions (3)Used By (0)

Laravel query class
===================

[](#laravel-query-class)

[![](https://camo.githubusercontent.com/27d2a0ad333374618b2a2cd2c9620a033e353d10c30b085112879997f9f4723d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305175657279253230436c6173732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d417269656c4d656a69614465762532466c61726176656c2d71756572792d636c617373267061747465726e3d746963546163546f65267374796c653d7374796c655f31266465736372697074696f6e3d68656c70732b746f2b68616e646c652b72657175657374732b776974682b6d756c7469706c652b66696c746572732532432b736f7274732b616e642b696e636c75646573266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)](https://camo.githubusercontent.com/27d2a0ad333374618b2a2cd2c9620a033e353d10c30b085112879997f9f4723d/68747470733a2f2f62616e6e6572732e6265796f6e64636f2e64652f4c61726176656c2532305175657279253230436c6173732e706e673f7468656d653d6c69676874267061636b6167654d616e616765723d636f6d706f7365722b72657175697265267061636b6167654e616d653d417269656c4d656a69614465762532466c61726176656c2d71756572792d636c617373267061747465726e3d746963546163546f65267374796c653d7374796c655f31266465736372697074696f6e3d68656c70732b746f2b68616e646c652b72657175657374732b776974682b6d756c7469706c652b66696c746572732532432b736f7274732b616e642b696e636c75646573266d643d312673686f7757617465726d61726b3d3026666f6e7453697a653d313030707826696d616765733d68747470732533412532462532466c61726176656c2e636f6d253246696d672532466c6f676f6d61726b2e6d696e2e737667)

[![Latest Version on Packagist](https://camo.githubusercontent.com/f0c875accae14e7aafa22fced34f5c3c774b36e0d0ae995549a1feaf4b163641/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f617269656c6d656a69616465762f6c61726176656c2d71756572792d636c6173732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arielmejiadev/laravel-query-class)[![Total Downloads](https://camo.githubusercontent.com/01f62e98cbddb1d3e544a2bf548fc8205dad0b49cd10e8234dfc830b9aa5c412/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f617269656c6d656a69616465762f6c61726176656c2d71756572792d636c6173732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/arielmejiadev/laravel-query-class)[![GitHub Actions](https://github.com/arielmejiadev/laravel-query-class/actions/workflows/main.yml/badge.svg)](https://github.com/arielmejiadev/laravel-query-class/actions/workflows/main.yml/badge.svg)

It generates query classes to handle requests with multiple filters, sorts and includes.

The idea comes as a tip from a [LaraconUS 2019 talk from Freek Van der Herten](https://youtu.be/FxACh4X-Xc0?t=1448)

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

[](#installation)

You can install the package via composer:

```
composer require arielmejiadev/laravel-query-class --dev
```

Stubs &amp; Commands installation
---------------------------------

[](#stubs--commands-installation)

```
php artisan query-class:install
```

Usage
-----

[](#usage)

```
php artisan make:query Users/UserQuery --model=User
```

It would generate a class in `app/Http/Queries/Users/UserQuery.php`:

You can choose if your query class would extend from `Spatie Query Builder` (REST API STANDARD) of from an `Eloquent` query class (for custom cases).

[![Screen Shot 2021-07-12 at 23 03 53](https://user-images.githubusercontent.com/31971074/125394326-c66af600-e366-11eb-8344-a9be05b8fcb1.png)](https://user-images.githubusercontent.com/31971074/125394326-c66af600-e366-11eb-8344-a9be05b8fcb1.png)

```
namespace App\Http\Queries\Users;

use App\Models\User;
use Spatie\QueryBuilder\QueryBuilder;

class UserQuery extends QueryBuilder
{
    public function __construct()
    {
        parent::__construct(User::query());

        $this->allowedFilters('updated_at', 'created_at')
            ->allowedSorts('created_at')
            ->allowedIncludes('team');
    }
}
```

You can chain any Eloquent method or if you choose Spatie Query Builder methods from both tools.

Now you can inject the Query Class in any controller constructor and the Laravel container will resolve it by itself.

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

### Security

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Ariel Mejia Dev](https://github.com/arielmejiadev)
- [Freek Van der Herten](https://github.com/freekmurze)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Total

2

Last Release

1766d ago

### Community

Maintainers

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

---

Top Contributors

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

---

Tags

arielmejiadevlaravel-query-class

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[mailerlite/laravel-elasticsearch

An easy way to use the official PHP ElasticSearch client in your Laravel applications.

934529.3k2](/packages/mailerlite-laravel-elasticsearch)[jeroen-g/explorer

Next-gen Elasticsearch driver for Laravel Scout.

397612.3k](/packages/jeroen-g-explorer)[swisnl/laravel-fulltext

Fulltext indexing and searching for Laravel

184104.5k6](/packages/swisnl-laravel-fulltext)[romanstruk/manticore-scout-engine

Laravel Manticore Scout Engine

4818.1k](/packages/romanstruk-manticore-scout-engine)[statamic-rad-pack/meilisearch

meilisearch search driver for Statamic

1661.7k](/packages/statamic-rad-pack-meilisearch)[internachi/blade-alpine-instantsearch

Algolia instant search as Blade/Alpine.js components

1940.9k](/packages/internachi-blade-alpine-instantsearch)

PHPackages © 2026

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