# spatie/laravel-query-builder

Easily build Eloquent queries from API requests

Repository: https://github.com/spatie/laravel-query-builder
Canonical: https://ross.abutalabs.com/products/laravel-query-builder
Homepage: https://spatie.be/docs/laravel-query-builder
Language: PHP
License: MIT
License Family: permissive
Topics: api, laravel, php, hacktoberfest
Last push: 2026-08-07T11:51:27+00:00

## Health v2 (maintenance only)
Score: 97/100 (v2, computed 2026-09-02T17:46:02.011165+00:00)
- activity 96, release rhythm 96, longevity 100
- inputs: {"age_days": 3152, "days_push": 26, "days_rel": 26, "gap_med": 12.5, "n_releases_24m": 25}
- flags: none
- formula: round(0.45*activity + 0.35*rhythm + 0.20*longevity); archived -> min(score, 10)

## Adoption (not part of the score)
Stars 4465, forks 420 (observed 2026-08-28T04:08:50.855149+00:00)

## What it is
A Laravel package that builds Eloquent queries from API request parameters, supporting filtering, sorting, field selection, and relationship includes following JSON API conventions. It extends Laravel's default Eloquent builder so existing query methods and macros remain available.

## Use cases
- filter api results by query parameters
- sort collections from a request in laravel
- allow clients to include relationships in api responses
- build json api compliant query parameters
- securely whitelist filters and sorts on eloquent queries
- add search and pagination filters to a rest api

## When to choose
- you build Laravel APIs and want request-driven filtering, sorting, and includes
- you want JSON API-style query parameters with whitelisting for safety
- you want to compose on top of existing Eloquent queries and scopes

## When to avoid
- your project is not Laravel/PHP
- you need complex custom query logic better expressed in dedicated repository classes
- you use a non-Eloquent data source

## Facets
- artifact type: library
- maturity: stable
- function: orm, api-framework, routing
- domain: web-development, backend, apis, databases
- platform: php
- tags: laravel, eloquent, json-api, query-filtering, spatie, web-server

## Member repositories
- spatie/laravel-query-builder (main) score 97

## Provenance
- Observed fields: from GitHub, fetched 2026-08-28T04:08:50.855149+00:00.
- Health v2: computed from the inputs above; adoption is never an input.
- Inferred fields (summary, facets, guidance): AI-extracted, prompt v1, taxonomy v1, on 2026-08-29T18:20:39.539527+00:00, confidence not recorded.
  - readme: https://github.com/spatie/laravel-query-builder (fetched 2026-08-28T04:08:50.855149+00:00, sha 9ca124136c68)
  - homepage: https://spatie.be/docs/laravel-query-builder (fetched 2026-08-29T09:07:29.285007+00:00, sha fcf3c1f16d50)
  - site_page: https://spatie.be/docs (fetched 2026-08-29T09:07:29.294171+00:00, sha 08e024d86d95)
  - site_page: https://spatie.be/about-us (fetched 2026-08-29T09:07:29.296393+00:00, sha d3cb88e4b34c)
  - site_page: https://spatie.be/docs/laravel-query-builder/v7 (fetched 2026-08-29T09:07:29.298156+00:00, sha 5d2366c7210b)
  - site_page: https://spatie.be/docs/laravel-query-builder/v6 (fetched 2026-08-29T09:07:29.299877+00:00, sha 6b1e85e23512)
  - site_page: https://spatie.be/docs/laravel-query-builder/v5 (fetched 2026-08-29T09:07:29.302122+00:00, sha a754641de91c)
  - site_page: https://spatie.be/docs/laravel-query-builder/v4 (fetched 2026-08-29T09:07:29.303922+00:00, sha 3710b586c349)
  - site_page: https://spatie.be/docs/laravel-query-builder/v3 (fetched 2026-08-29T09:07:29.305508+00:00, sha b6dc0ef0af60)
  - site_page: https://spatie.be/docs/laravel-query-builder/v2 (fetched 2026-08-29T09:07:29.307090+00:00, sha 303c29cda3c8)
- Data as of 2026-08-30T08:39:29.467469+00:00.
