PHPackages                             nadlambino/laravel-query-builder - 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. [API Development](/categories/api)
4. /
5. nadlambino/laravel-query-builder

ActiveLibrary[API Development](/categories/api)

nadlambino/laravel-query-builder
================================

This is a forked of spatie/laravel-query-builder but decoupled the builder from request.

7.0.1(1y ago)023MITPHPPHP ^8.2

Since Jun 21Pushed 1y agoCompare

[ Source](https://github.com/nadlambino/laravel-query-builder)[ Packagist](https://packagist.org/packages/nadlambino/laravel-query-builder)[ Docs](https://github.com/nadlambino/laravel-query-builder)[ Fund](https://spatie.be/open-source/support-us)[ RSS](/packages/nadlambino-laravel-query-builder/feed)WikiDiscussions main Synced 1mo ago

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

What is the goal for forking this package?
==========================================

[](#what-is-the-goal-for-forking-this-package)

The goal is to allow the `QueryBuilder` class to not be tightly coupled from the request object. The package should be able to use outside of the context of API request, write a single query builder that can be use with API and in any other part of the application where the filters are not from the request.

What are the changes?
=====================

[](#what-are-the-changes)

- First, the package namespace was changed to avoid conflict and confusion from the `spatie/laravel-query-builder`.
- Renamed the `QueryBuilderRequest` to `RequestSource` and move it into the `sources` directory. The namespace were also changed due to moving it to its new location.
- Created a `CollectionSource` which shares the same methods from the `RequestSource` via `Source` trait. The only difference is how the `getData` (previously `getRequestData`) was implemented.
- Changing the delimeter can now be done through the source class. Previously, it can be done using the `QueryBuilderRequest`

```
/** Previously */
QueryBuilderRequest::setFilterArrayValueDelimiter('|');

/** Now, when using the request as the source */
RequestSource::setFilterArrayValueDelimiter('|');

/** Or when using the array/collection as the source */
CollectionSource::setFilterArrayValueDelimiter('|');
```

Build Eloquent queries from API requests
========================================

[](#build-eloquent-queries-from-api-requests)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4e0d6643bad272dbce941b7a77c1bb874065ea3537828d2126d1f076dd654488/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7370617469652f6c61726176656c2d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-query-builder)[![Test Status](https://camo.githubusercontent.com/a0885c500ddb31039850c032248115ca3cf27aa27ee9dcdbd6194006d2a136be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d71756572792d6275696c6465722f72756e2d74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d61696e)](https://camo.githubusercontent.com/a0885c500ddb31039850c032248115ca3cf27aa27ee9dcdbd6194006d2a136be/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d71756572792d6275696c6465722f72756e2d74657374732e796d6c3f6c6162656c3d7465737473266272616e63683d6d61696e)[![Code Style Status](https://camo.githubusercontent.com/9326f0b5e1da41bc6c7775fec2efd7fb43438dc66b238cf125da16260fee8cb0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d71756572792d6275696c6465722f7068702d63732d66697865722e796d6c3f6c6162656c3d636f64652532307374796c65266272616e63683d6d61696e)](https://camo.githubusercontent.com/9326f0b5e1da41bc6c7775fec2efd7fb43438dc66b238cf125da16260fee8cb0/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f7370617469652f6c61726176656c2d71756572792d6275696c6465722f7068702d63732d66697865722e796d6c3f6c6162656c3d636f64652532307374796c65266272616e63683d6d61696e)[![Total Downloads](https://camo.githubusercontent.com/b06894bff55703ad61b99a25a3d21a081bce61e0bfee82d517a8c73073031d3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7370617469652f6c61726176656c2d71756572792d6275696c6465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/spatie/laravel-query-builder)

This package allows you to filter, sort and include eloquent relations based on a request. The `QueryBuilder` used in this package extends Laravel's default Eloquent builder. This means all your favorite methods and macros are still available. Query parameter names follow the [JSON API specification](http://jsonapi.org/) as closely as possible.

Basic usage
-----------

[](#basic-usage)

### Filter a query based on a request: `/users?filter[name]=John`:

[](#filter-a-query-based-on-a-request-usersfilternamejohn)

```
use Spatie\QueryBuilder\QueryBuilder;

$users = QueryBuilder::for(User::class)
    ->allowedFilters('name')
    ->get();

// all `User`s that contain the string "John" in their name
```

[Read more about filtering features like: partial filters, exact filters, scope filters, custom filters, ignored values, default filter values, ...](https://spatie.be/docs/laravel-query-builder/v5/features/filtering/)

### Including relations based on a request: `/users?include=posts`:

[](#including-relations-based-on-a-request-usersincludeposts)

```
$users = QueryBuilder::for(User::class)
    ->allowedIncludes('posts')
    ->get();

// all `User`s with their `posts` loaded
```

[Read more about include features like: including nested relationships, including relationship count, custom includes, ...](https://spatie.be/docs/laravel-query-builder/v5/features/including-relationships/)

### Sorting a query based on a request: `/users?sort=id`:

[](#sorting-a-query-based-on-a-request-userssortid)

```
$users = QueryBuilder::for(User::class)
    ->allowedSorts('id')
    ->get();

// all `User`s sorted by ascending id
```

[Read more about sorting features like: custom sorts, sort direction, ...](https://spatie.be/docs/laravel-query-builder/v5/features/sorting/)

### Works together nicely with existing queries:

[](#works-together-nicely-with-existing-queries)

```
$query = User::where('active', true);

$userQuery = QueryBuilder::for($query) // start from an existing Builder instance
    ->withTrashed() // use your existing scopes
    ->allowedIncludes('posts', 'permissions')
    ->where('score', '>', 42); // chain on any of Laravel's query builder methods
```

### Selecting fields for a query: `/users?fields[users]=id,email`

[](#selecting-fields-for-a-query-usersfieldsusersidemail)

```
$users = QueryBuilder::for(User::class)
    ->allowedFields(['id', 'email'])
    ->get();

// the fetched `User`s will only have their id & email set
```

[Read more about selecting fields.](https://spatie.be/docs/laravel-query-builder/v5/features/selecting-fields/)

Support us
----------

[](#support-us)

[![](https://camo.githubusercontent.com/34a9aa47ed3155462cc3b66ff5b4252f457b4e911ccaf26eb9c6c62ec4b031f8/68747470733a2f2f6769746875622d6164732e73332e65752d63656e7472616c2d312e616d617a6f6e6177732e636f6d2f6c61726176656c2d71756572792d6275696c6465722e6a70673f743d31)](https://spatie.be/github-ad-click/laravel-query-builder)

We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).

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

[](#installation)

You can install the package via composer:

```
composer require spatie/laravel-query-builder
```

Read the installation notes on the docs site: [https://spatie.be/docs/laravel-query-builder/v5/installation-setup](https://spatie.be/docs/laravel-query-builder/v5/installation-setup/).

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

[](#documentation)

You can find the documentation on .

Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the media library? Feel free to [create an issue on GitHub](https://github.com/spatie/laravel-query-builder/issues), we'll try to address it as soon as possible.

If you've found a bug regarding security please mail  instead of using the issue tracker.

### Upgrading

[](#upgrading)

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

### Testing

[](#testing)

```
composer test
```

### Changelog

[](#changelog)

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

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

[](#contributing)

Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.

### Security

[](#security)

If you've found a bug regarding security please mail  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Alex Vanderbist](https://github.com/AlexVanderbist)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance32

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

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

691d ago

### Community

Maintainers

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

---

Top Contributors

[![AlexVanderbist](https://avatars.githubusercontent.com/u/6287961?v=4)](https://github.com/AlexVanderbist "AlexVanderbist (391 commits)")[![freekmurze](https://avatars.githubusercontent.com/u/483853?v=4)](https://github.com/freekmurze "freekmurze (257 commits)")[![dominikb](https://avatars.githubusercontent.com/u/28777818?v=4)](https://github.com/dominikb "dominikb (15 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (11 commits)")[![nadlambino](https://avatars.githubusercontent.com/u/50892397?v=4)](https://github.com/nadlambino "nadlambino (10 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (10 commits)")[![stevebauman](https://avatars.githubusercontent.com/u/6421846?v=4)](https://github.com/stevebauman "stevebauman (9 commits)")[![AdrianMrn](https://avatars.githubusercontent.com/u/12762044?v=4)](https://github.com/AdrianMrn "AdrianMrn (8 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (8 commits)")[![Nielsvanpach](https://avatars.githubusercontent.com/u/10651054?v=4)](https://github.com/Nielsvanpach "Nielsvanpach (6 commits)")[![cornelp](https://avatars.githubusercontent.com/u/10222052?v=4)](https://github.com/cornelp "cornelp (6 commits)")[![klimov-paul](https://avatars.githubusercontent.com/u/1482054?v=4)](https://github.com/klimov-paul "klimov-paul (5 commits)")[![brendt](https://avatars.githubusercontent.com/u/6905297?v=4)](https://github.com/brendt "brendt (5 commits)")[![drbyte](https://avatars.githubusercontent.com/u/404472?v=4)](https://github.com/drbyte "drbyte (4 commits)")[![enricodelazzari](https://avatars.githubusercontent.com/u/10452445?v=4)](https://github.com/enricodelazzari "enricodelazzari (4 commits)")[![vyuldashev](https://avatars.githubusercontent.com/u/1809081?v=4)](https://github.com/vyuldashev "vyuldashev (4 commits)")[![ntzm](https://avatars.githubusercontent.com/u/3888578?v=4)](https://github.com/ntzm "ntzm (4 commits)")[![patinthehat](https://avatars.githubusercontent.com/u/5508707?v=4)](https://github.com/patinthehat "patinthehat (4 commits)")[![Medalink](https://avatars.githubusercontent.com/u/201221?v=4)](https://github.com/Medalink "Medalink (3 commits)")[![JustSteveKing](https://avatars.githubusercontent.com/u/6368379?v=4)](https://github.com/JustSteveKing "JustSteveKing (3 commits)")

---

Tags

spatielaravel-query-builderNadLambino

###  Code Quality

TestsPest

### Embed Badge

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

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

###  Alternatives

[spatie/laravel-query-builder

Easily build Eloquent queries from API requests

4.4k26.9M220](/packages/spatie-laravel-query-builder)[spatie/laravel-activitylog

A very simple activity logger to monitor the users of your website or application

5.8k45.4M309](/packages/spatie-laravel-activitylog)[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[spatie/laravel-health

Monitor the health of a Laravel application

85810.0M83](/packages/spatie-laravel-health)[spatie/laravel-enum

Laravel Enum support

3655.4M31](/packages/spatie-laravel-enum)

PHPackages © 2026

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