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/1.basics/1.resources.md
+31-9Lines changed: 31 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -37,6 +37,21 @@ class ProductResource extends Resource
37
37
}
38
38
```
39
39
40
+
## Static Construction
41
+
42
+
Use `Resource::make()` to serialize a model into a JSON:API array without going through a controller or response object. This resolves the resource from the container and calls `toArray()`:
This is useful for embedding resource data inside jobs, events, or notifications where you do not need a full HTTP response.
54
+
40
55
## Type and ID Resolution
41
56
42
57
By default, the toolkit resolves:
@@ -49,6 +64,8 @@ By default, the toolkit resolves:
49
64
Override `resolveId()` on your resource for full control. This takes precedence over the global resolver:
50
65
51
66
```php
67
+
use BlueBeetle\ApiToolkit\Resources\Resource;
68
+
52
69
class ProductResource extends Resource
53
70
{
54
71
protected string $type = 'products';
@@ -144,7 +161,7 @@ The `self()` link is automatically merged with any additional links from `links(
144
161
145
162
## OpenAPI Schema
146
163
147
-
Define attribute types for automatic OpenAPI spec generation. The `schema()` method controls how your resource's attributes appear in the generated OpenAPI document.
164
+
Define attribute types for automatic [OpenAPI spec generation](/docs/api-toolkit/latest/advanced/openapi). The `schema()` method controls how your resource's attributes appear in the generated OpenAPI document.
148
165
149
166
### Using String Shorthands
150
167
@@ -187,15 +204,20 @@ Available shorthands:
187
204
For more control, pass OpenAPI property objects directly. You can mix shorthands and full definitions:
Copy file name to clipboardExpand all lines: docs/1.basics/2.responses.md
+62-5Lines changed: 62 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,28 @@ class ProductController
76
76
}
77
77
```
78
78
79
+
### Merging Meta and Links
80
+
81
+
Calling `meta()` or `links()` multiple times merges the values rather than replacing them. This is useful when different parts of your code need to add their own metadata:
82
+
83
+
```php
84
+
use App\Http\Resources\ProductResource;
85
+
use App\Models\Product;
86
+
use BlueBeetle\ApiToolkit\Http\Response;
87
+
88
+
class ProductController
89
+
{
90
+
public function show(Product $product, Response $response)
Copy file name to clipboardExpand all lines: docs/1.basics/3.query-builder.md
+60-2Lines changed: 60 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -74,7 +74,7 @@ Then in your controller, `fromResource()` picks up all of these automatically.
74
74
75
75
## Overriding Resource Configuration
76
76
77
-
Method calls take priority over resource definitions:
77
+
Method calls on the QueryBuilder take priority over resource definitions. If you call `allowedFilters()`, `allowedSorts()`, `defaultSort()`, or `allowedIncludes()` on the builder, those values replace whatever the resource defines. This lets you reuse the same resource class across endpoints while customizing behavior per route.
78
78
79
79
```php
80
80
use App\Http\Resources\ProductResource;
@@ -135,7 +135,9 @@ class ProductController
135
135
136
136
## Apply Without Fetching
137
137
138
-
Use `apply()` to apply filters, sorts, and includes without executing the query. This is useful when you need the modified query for something other than a standard response, like counting or exporting:
138
+
Use `apply()` to apply filters, sorts, and includes without executing the query. This returns the QueryBuilder instance, so you can call `getQuery()` to access the underlying Eloquent builder. This is useful when you need the modified query for something other than a standard response.
`getQuery()` returns the underlying `Illuminate\Database\Eloquent\Builder` instance. You can call it at any time, but it is most useful after `apply()` so the builder already has all filters, sorts, and includes applied. The returned builder is a standard Eloquent builder, so you can chain any Eloquent method on it.
0 commit comments