Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
6d29e56
Add issue #175 link in selecting-fields.md
alipadron Jun 14, 2024
0560057
Merge pull request #951 from alipadron/patch-1
freekmurze Jun 14, 2024
663b5b6
Update filtering.md
justinkekeocha Jun 30, 2024
45af547
Merge pull request #954 from justinkekeocha/patch-3
freekmurze Jul 3, 2024
0eb0ffd
Bump dependabot/fetch-metadata from 2.1.0 to 2.2.0
dependabot[bot] Jul 8, 2024
ed71451
Merge pull request #955 from spatie/dependabot/github_actions/dependa…
github-actions[bot] Jul 8, 2024
55aa90b
Merge pull request #7 from kjsoftware/v2
thuijbers Jul 31, 2024
8e2673f
[DOCS] Update Frontend implementation with a new one
cgarciagarcia Aug 3, 2024
8c9d597
Merge pull request #961 from cgarciagarcia/patch-1
freekmurze Aug 5, 2024
0eb7bcc
AllowedFilter should return static rather than self.
walterk-wmt Aug 14, 2024
ee31e0c
Update selecting-fields.md
chengkangzai Sep 16, 2024
edd9b1c
Merge pull request #969 from chengkangzai/patch-1
Nielsvanpach Sep 23, 2024
fb28926
Fix styling
Nielsvanpach Sep 23, 2024
f3c7828
Merge pull request #964 from kosarinin/allowed-filter-should-return-s…
Nielsvanpach Sep 23, 2024
34f35ce
Update CHANGELOG
Nielsvanpach Sep 23, 2024
09d9162
Add operator filter (<, =, >, ...) (#940)
AbdelrahmanBl Sep 27, 2024
474b341
Fix styling
AlexVanderbist Sep 27, 2024
b8bf3fd
Add documentation for the operator filter (#974)
AlexVanderbist Sep 27, 2024
46018b3
Update CHANGELOG
AlexVanderbist Sep 27, 2024
bc2daf1
Removed explicit escaping for pgsql driver in FilterPartial#maybeSpec…
Talpx1 Oct 3, 2024
64f0453
Fix phpstan issue
AlexVanderbist Oct 3, 2024
9ee7549
Update CHANGELOG
AlexVanderbist Oct 3, 2024
cf1cb4c
Add additional tests
AlexVanderbist Oct 3, 2024
5dd89d1
Fix styling
AlexVanderbist Oct 3, 2024
9fd030e
Update larastan/phpstan
AlexVanderbist Oct 3, 2024
8012da9
Update filtering.md to clarify handling of array scope parameter (#976)
g-gullstrand Oct 18, 2024
59e3157
Fixed IncludedCount.php
dash8x Oct 19, 2024
b1b6b2c
add .phpunit.cache to .gitignore
outer0906 Nov 12, 2024
5c98ec6
Merge pull request #982 from tarexme/fix/phpunit-cache
Nielsvanpach Nov 18, 2024
47d86e2
Fix typo in filtering.md
yngc0der Dec 6, 2024
342f30f
Merge pull request #984 from yngc0der/patch-1
freekmurze Dec 9, 2024
b25d021
Merge pull request #978 from dash8x/patch-1
freekmurze Dec 11, 2024
d12e6b7
Update CHANGELOG
freekmurze Dec 11, 2024
e5af869
Fix selecting fields on belongs to many relations
Dec 23, 2024
52749b2
Merge pull request #986 from rasmuscnielsen/patch-field-selection-on-…
freekmurze Dec 23, 2024
db9fb45
Update CHANGELOG
freekmurze Dec 23, 2024
0348ab0
New Filter belongs to (#975)
gpibarra Dec 23, 2024
de6a10d
Update docs to v6
AlexVanderbist Dec 23, 2024
d064882
Tweak tests
AlexVanderbist Dec 23, 2024
cf5350e
feat: implement a way of matching the fields to the jsonapi spec (#983)
CoolGoose Dec 23, 2024
9674601
Delete utils/run_tests.sh
AlexVanderbist Dec 23, 2024
1818565
Update CHANGELOG
AlexVanderbist Dec 23, 2024
d96c963
General code health improvements (#988)
xHeaven Dec 30, 2024
c183430
Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0
dependabot[bot] Jan 27, 2025
dc7c17a
Merge pull request #992 from spatie/dependabot/github_actions/dependa…
github-actions[bot] Jan 27, 2025
db8cb6c
Exclude .github folder and .php_cs from being included in composer do…
stevebauman Feb 18, 2025
01bb302
Bump dependencies for Laravel 12
laravel-shift Feb 19, 2025
8feb781
Update GitHub Actions for Laravel 12
laravel-shift Feb 19, 2025
743f5b6
Update run-tests.yml
freekmurze Feb 19, 2025
9844a7c
Merge pull request #994 from laravel-shift/l12-compatibility
freekmurze Feb 19, 2025
71b89e5
Update run-tests.yml
freekmurze Feb 19, 2025
278ee9c
Update run-tests.yml
freekmurze Feb 19, 2025
fadf8a2
Merge pull request #993 from stevebauman/patch-1
freekmurze Feb 19, 2025
465d9b7
Update composer.json
freekmurze Feb 19, 2025
a3cd80d
Update CHANGELOG
freekmurze Feb 21, 2025
e01179f
Update README.md
jimirobaer Apr 8, 2025
c3a7637
Enhance QueryBuilder with generics support for better type inference
alexkart Apr 15, 2025
f73be49
Refactor clone method in QueryBuilder to improve type safety with gen…
alexkart Apr 15, 2025
fc20733
revert some changes
alexkart Apr 15, 2025
3675f7b
Merge pull request #1002 from alexkart/query-buikder-generic
freekmurze Apr 16, 2025
1d9de6d
Update CHANGELOG
freekmurze Apr 16, 2025
87e7a96
Update README.md
jimirobaer Apr 22, 2025
ff95255
update some links so point to v6 docs
KnudH May 3, 2025
9083970
Merge pull request #1004 from KnudH/patch-1
freekmurze May 3, 2025
7de97f9
Bump dependabot/fetch-metadata from 2.3.0 to 2.4.0
dependabot[bot] May 12, 2025
9b48223
Merge pull request #1006 from spatie/dependabot/github_actions/depend…
github-actions[bot] May 12, 2025
e0d1db5
Fix styling
ruuddeenen May 15, 2025
57b8290
RDT-440
ruuddeenen May 15, 2025
06f64fa
Merge remote-tracking branch 'origin/issue/RDT-440' into issue/RDT-440
ruuddeenen May 15, 2025
6b5bf0c
Fix styling
ruuddeenen May 15, 2025
db7ae84
Merge branch 'v3' into issue/RDT-440
kjrobin May 22, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@
* text eol=lf

# Ignore all test and documentation with "export-ignore".
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.travis.yml export-ignore
/phpunit.xml.dist export-ignore
/.php_cs.dist.php export-ignore
/.scrutinizer.yml export-ignore
/tests export-ignore
/.editorconfig export-ignore
2 changes: 1 addition & 1 deletion .github/workflows/dependabot-auto-merge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.1.0
uses: dependabot/fetch-metadata@v2.4.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
compat-lookup: true
Expand Down
127 changes: 59 additions & 68 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,82 +1,73 @@
name: run-tests

on:
push:
paths:
- '**.php'
- '.github/workflows/run-tests.yml'
- 'phpunit.xml.dist'
- 'composer.json'
- 'composer.lock'
push

jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.3, 8.2]
laravel: [10.*, 11.*]
stability: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
carbon: ^2.63
- laravel: 10.*
testbench: 8.*
test:
runs-on: ${{ matrix.os }}

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}
timeout-minutes: 5

services:
mysql:
image: mysql:8.0
env:
MYSQL_USER: user
MYSQL_PASSWORD: secret
MYSQL_DATABASE: laravel_query_builder
MYSQL_ROOT_PASSWORD: secretroot
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest]
php: [8.4, 8.3, 8.2]
laravel: ['10.*', '11.*', '12.*']
stability: [prefer-stable]
include:
- laravel: 11.*
testbench: 9.*
- laravel: 10.*
testbench: 8.*
- laravel: 12.*
testbench: 10.*

redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v4
services:
mysql:
image: mysql:8.0
env:
MYSQL_USER: user
MYSQL_PASSWORD: secret
MYSQL_DATABASE: laravel_query_builder
MYSQL_ROOT_PASSWORD: secretroot
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
redis:
image: redis
ports:
- 6379:6379
options: --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo
coverage: none

- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction
- name: Setup problem matchers
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"

- name: Execute tests
run: vendor/bin/pest
env:
DB_USERNAME: user
DB_PASSWORD: secret
DB_PORT: ${{ job.services.mysql.ports[3306] }}
REDIS_PORT: 6379
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.stability }} --prefer-dist --no-interaction

- name: Execute tests
run: vendor/bin/pest
env:
DB_USERNAME: user
DB_PASSWORD: secret
DB_PORT: ${{ job.services.mysql.ports[3306] }}
REDIS_PORT: 6379
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ composer.lock
vendor
.php_cs.cache
coverage
.phpunit.cache
.phpunit.result.cache
/.idea
.php-cs-fixer.cache

1 change: 0 additions & 1 deletion .phpunit.cache/test-results

This file was deleted.

112 changes: 112 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,118 @@

All notable changes to `laravel-query-builder` will be documented in this file

## 6.3.2 - 2025-04-16

### What's Changed

* Enhance QueryBuilder with generics support for better type inference by @alexkart in https://github.com/spatie/laravel-query-builder/pull/1002

### New Contributors

* @alexkart made their first contribution in https://github.com/spatie/laravel-query-builder/pull/1002

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.3.1...6.3.2

## 6.3.1 - 2025-02-21

### What's Changed

* General code health improvements by @xHeaven in https://github.com/spatie/laravel-query-builder/pull/988
* Bump dependabot/fetch-metadata from 2.2.0 to 2.3.0 by @dependabot in https://github.com/spatie/laravel-query-builder/pull/992
* Laravel 12.x Compatibility by @laravel-shift in https://github.com/spatie/laravel-query-builder/pull/994
* Exclude `.github` folder and `.php_cs` from being included in composer installation by @stevebauman in https://github.com/spatie/laravel-query-builder/pull/993

### New Contributors

* @xHeaven made their first contribution in https://github.com/spatie/laravel-query-builder/pull/988

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.3.0...6.3.1

## 6.3.0 - 2024-12-23

### What's Changed

* Feature: Add "belongs to" filter by @gpibarra in https://github.com/spatie/laravel-query-builder/pull/975
* Feature: Additional config options to better match the API spec by @CoolGoose in https://github.com/spatie/laravel-query-builder/pull/983

### New Contributors

* @CoolGoose made their first contribution in https://github.com/spatie/laravel-query-builder/pull/983

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.2.3...6.3.0

## 6.2.3 - 2024-12-23

### What's Changed

* Fix selecting fields on belongs to many relations by @rasmuscnielsen in https://github.com/spatie/laravel-query-builder/pull/986

### New Contributors

* @rasmuscnielsen made their first contribution in https://github.com/spatie/laravel-query-builder/pull/986

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.2.2...6.2.3

## 6.2.2 - 2024-12-11

### What's Changed

* Update filtering.md to clarify handling of array scope parameter by @g-gullstrand in https://github.com/spatie/laravel-query-builder/pull/976
* Remove PHPUnit cache by @tarexme in https://github.com/spatie/laravel-query-builder/pull/982
* Fix typo in filtering.md by @yngc0der in https://github.com/spatie/laravel-query-builder/pull/984
* Fixed IncludedCount.php by @dash8x in https://github.com/spatie/laravel-query-builder/pull/978

### New Contributors

* @g-gullstrand made their first contribution in https://github.com/spatie/laravel-query-builder/pull/976
* @tarexme made their first contribution in https://github.com/spatie/laravel-query-builder/pull/982
* @yngc0der made their first contribution in https://github.com/spatie/laravel-query-builder/pull/984
* @dash8x made their first contribution in https://github.com/spatie/laravel-query-builder/pull/978

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.2.1...6.2.2

## 6.2.1 - 2024-10-03

### What's Changed

* Removed explicit escaping for `pgsql` driver in `FiltersPartial` - Fixes #941 by @Talpx1 in https://github.com/spatie/laravel-query-builder/pull/968

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.2.0...6.2.1

## 6.2.0 - 2024-09-27

### What's Changed

* [FEAT] add filter by operator by @AbdelrahmanBl in https://github.com/spatie/laravel-query-builder/pull/940
* Add documentation for the operator filter by @AlexVanderbist in https://github.com/spatie/laravel-query-builder/pull/974

### New Contributors

* @AbdelrahmanBl made their first contribution in https://github.com/spatie/laravel-query-builder/pull/940

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.1.0...6.2.0

## 6.1.0 - 2024-09-23

### What's Changed

* Bump ramsey/composer-install from 2 to 3 by @dependabot in https://github.com/spatie/laravel-query-builder/pull/939
* Add issue #175 link in selecting-fields.md by @alipadron in https://github.com/spatie/laravel-query-builder/pull/951
* Update filtering.md by @justinkekeocha in https://github.com/spatie/laravel-query-builder/pull/954
* Bump dependabot/fetch-metadata from 2.1.0 to 2.2.0 by @dependabot in https://github.com/spatie/laravel-query-builder/pull/955
* [DOCS] Update Frontend implementation with a new one by @cgarciagarcia in https://github.com/spatie/laravel-query-builder/pull/961
* Update Documentation for php markdown by @chengkangzai in https://github.com/spatie/laravel-query-builder/pull/969
* AllowedFilter should return static rather than self by @kosarinin in https://github.com/spatie/laravel-query-builder/pull/964

### New Contributors

* @alipadron made their first contribution in https://github.com/spatie/laravel-query-builder/pull/951
* @cgarciagarcia made their first contribution in https://github.com/spatie/laravel-query-builder/pull/961
* @chengkangzai made their first contribution in https://github.com/spatie/laravel-query-builder/pull/969
* @kosarinin made their first contribution in https://github.com/spatie/laravel-query-builder/pull/964

**Full Changelog**: https://github.com/spatie/laravel-query-builder/compare/6.0.1...6.1.0

## 6.0.1 - 2024-05-21

### What's Changed
Expand Down
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Build Eloquent queries from API requests
<div align="left">
<a href="https://spatie.be/open-source?utm_source=github&utm_medium=banner&utm_campaign=laravel-query-builder">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://spatie.be/packages/header/laravel-query-builder/html/dark.webp">
<img alt="Logo for laravel-query-builder" src="https://spatie.be/packages/header/laravel-query-builder/html/light.webp" height="190">
</picture>
</a>

<h1>Build Eloquent queries from API requests</h1>

[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-query-builder.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-query-builder)
![Test Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-query-builder/run-tests.yml?label=tests&branch=main)
![Code Style Status](https://img.shields.io/github/actions/workflow/status/spatie/laravel-query-builder/php-cs-fixer.yml?label=code%20style&branch=main)
[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-query-builder.svg?style=flat-square)](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.
</div>

## Caching foreign keys
Add this line to your composer.json file to cache foreign keys. This will allow the query builder to automatically detect foreign keys without having to make a database call.
Expand Down
13 changes: 6 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,18 @@
],
"require": {
"php": "^8.2",
"illuminate/database": "^10.0|^11.0",
"illuminate/http": "^10.0|^11.0",
"illuminate/support": "^10.0|^11.0",
"illuminate/database": "^10.0|^11.0|^12.0",
"illuminate/http": "^10.0|^11.0|^12.0",
"illuminate/support": "^10.0|^11.0|^12.0",
"spatie/laravel-package-tools": "^1.11",
"doctrine/dbal": "^3.5"
},
"require-dev": {
"ext-json": "*",
"mockery/mockery": "^1.4",
"nunomaduro/larastan": "^2.0",
"orchestra/testbench": "^7.0|^8.0",
"phpunit/phpunit": "^10.0",
"pestphp/pest": "^2.0",
"orchestra/testbench": "^7.0|^8.0|^10.0",
"pestphp/pest": "^2.0|^3.7",
"phpunit/phpunit": "^10.0|^11.5.3",
"spatie/invade": "^2.0"
},
"autoload": {
Expand Down
19 changes: 19 additions & 0 deletions config/query-builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,23 @@
* GET /users?fields[userOwner]=id,name
*/
'convert_relation_names_to_snake_case_plural' => true,

/*
* By default, the package expects relationship names to be snake case plural when using fields[relationship].
* For example, fetching the id and name for a userOwner relation would look like this:
* GET /users?fields[user_owner]=id,name
*
* Set this to one of `snake_case`, `camelCase` or `none` if you want to enable table name resolution in addition to the relation name resolution
* GET /users?include=topOrders&fields[orders]=id,name
*/
'convert_relation_table_name_strategy' => false,

/*
* By default, the package expects the field names to match the database names
* For example, fetching the field named firstName would look like this:
* GET /users?fields=firstName
*
* Set this to `true` if you want to convert the firstName into first_name for the underlying query
*/
'convert_field_names_to_snake_case' => false,
];
2 changes: 1 addition & 1 deletion database/factories/AppendModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Spatie\QueryBuilder\Database\Factories;

use Spatie\QueryBuilder\Tests\TestClasses\Models\AppendModel;
use Illuminate\Database\Eloquent\Factories\Factory;
use Spatie\QueryBuilder\Tests\TestClasses\Models\AppendModel;

class AppendModelFactory extends Factory
{
Expand Down
1 change: 0 additions & 1 deletion database/factories/TestModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,3 @@ public function definition()
];
}
}

2 changes: 1 addition & 1 deletion docs/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: v5
title: v6
slogan: Easily build Eloquent queries from API requests.
githubUrl: https://github.com/spatie/laravel-query-builder
branch: main
Expand Down
3 changes: 2 additions & 1 deletion docs/advanced-usage/front-end-implementation.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: Front-end implementation
weight: 3
weight: 6
---

If you're interested in building query urls on the front-end to match this package, you could use one of the below:
Expand All @@ -11,3 +11,4 @@ If you're interested in building query urls on the front-end to match this packa
Pascal Baljet](https://github.com/pascalbaljet).
- React: [cogent-js package](https://www.npmjs.com/package/cogent-js) by [Joel Male](https://github.com/joelwmale).
- Typescript: [query-builder-ts package](https://www.npmjs.com/package/@vortechron/query-builder-ts) by [Amirul Adli](https://www.npmjs.com/~vortechron)
- Typescript + React [react-query-builder](https://www.npmjs.com/package/@cgarciagarcia/react-query-builder) by [Carlos Garcia](https://github.com/cgarciagarcia)
Loading
Loading