You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/query-builder/overview.mdx
+25-14Lines changed: 25 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Overview
3
3
description: Fluent query builder that ties everything together
4
4
---
5
5
6
-
The `QueryBuilder` is a fluent wrapper that applies filtering, sorting, includes, and pagination from the request. It reads defaults from your [Resource](/resources/overview) and allowing overrides.
6
+
The `QueryBuilder` is a fluent wrapper that applies filtering, sorting, includes, and pagination from the request. It reads defaults from your [Resource](/resources/overview) and allows overrides.
7
7
8
8
## Why use it?
9
9
@@ -18,13 +18,14 @@ $query = Product::query();
18
18
(new IncludeParser(allowed: [...]))->apply($request, $query);
19
19
20
20
$results = (new OffsetPaginator())->paginate($request, $query);
The QueryBuilder reads `allowedFilters()`, `allowedSorts()`, `defaultSort()`, and `allowedIncludes()` from the Resource and applies them automatically.
45
44
45
+
The terminal methods (`paginate()`, `cursorPaginate()`, `get()`) return a `SuccessResponse` that implements Laravel's `Responsable` interface. You can return it directly from controllers without calling `->respond()`.
46
+
46
47
## Starting from an existing query
47
48
48
49
You can pass an existing `Builder` instance instead of a model class:
Copy file name to clipboardExpand all lines: docs/responses/error-responses.mdx
+8-9Lines changed: 8 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,10 +3,12 @@ title: Error Responses
3
3
description: Build JSON:API error responses
4
4
---
5
5
6
+
`ErrorResponse` implements Laravel's `Responsable` interface. The HTTP status code is derived from the status you pass to `error()`, so you can return it directly without calling `->respond()`.
7
+
6
8
## Basic error
7
9
8
10
```php
9
-
return $this->response->error('Not Found', 'Product does not exist', 404)->respond();
11
+
return $this->response->error('Not Found', 'Product does not exist', 404);
10
12
```
11
13
12
14
```json
@@ -26,8 +28,7 @@ return $this->response->error('Not Found', 'Product does not exist', 404)->respo
26
28
```php
27
29
return $this->response
28
30
->error('Validation Error', 'Name is required', 422)
29
-
->code('validation_error')
30
-
->respond();
31
+
->code('validation_error');
31
32
```
32
33
33
34
```json
@@ -51,22 +52,20 @@ Point to the field that caused the error:
51
52
return $this->response
52
53
->error('Validation Error', 'Name is required', 422)
Copy file name to clipboardExpand all lines: docs/responses/overview.mdx
+18Lines changed: 18 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,24 @@ final class ProductController
20
20
}
21
21
```
22
22
23
+
## Responsable
24
+
25
+
Both `SuccessResponse` and `ErrorResponse` implement Laravel's `Responsable` interface. You can return them directly from controllers without calling `->respond()`:
0 commit comments