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-v3/content/docs/api/getters.md
+33-2Lines changed: 33 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,6 +143,27 @@ public function handle(Request $request)
143
143
}
144
144
```
145
145
146
+
#### Accessing the filtered query
147
+
148
+
For index getters, you can access the filtered query builder via `$request->filteredQuery()`. This query builder already has all filters, search queries, and other query modifiers applied by Restify:
149
+
150
+
```php
151
+
public function handle(Request $request): JsonResponse
152
+
{
153
+
// Get the filtered query builder with all applied filters, search, etc.
154
+
$query = $request->filteredQuery();
155
+
156
+
// You can further refine the query
157
+
$data = $query->where('status', 'active')->get();
158
+
159
+
return response()->json([
160
+
'data' => $data,
161
+
]);
162
+
}
163
+
```
164
+
165
+
This allows you to build upon the existing query without having to manually apply filters again.
166
+
146
167
## Getter customizations
147
168
148
169
Getters could be easily customized.
@@ -278,16 +299,26 @@ Index getters are used when you have to apply them for many items.
278
299
279
300
### Index getter definition
280
301
281
-
The index getter definition differs in how it receives arguments for the `handle` method.
302
+
The index getter definition receives only the `$request` in the `handle` method. You can access the filtered query builder using `$request->filteredQuery()`:
282
303
283
304
```php
284
305
public function handle(Request $request): JsonResponse
285
306
{
286
-
//
307
+
// Get the filtered query builder with all applied filters, search, etc.
308
+
$query = $request->filteredQuery();
309
+
310
+
// You can further refine the query
311
+
$data = $query->where('status', 'active')->get();
312
+
313
+
return response()->json([
314
+
'data' => $data,
315
+
]);
287
316
}
288
317
289
318
```
290
319
320
+
The filtered query builder contains all repository filters, search queries, and other query modifiers already applied. This allows you to leverage existing filters without re-implementing them.
321
+
291
322
### Index getter registration
292
323
293
324
To register an index getter, we have to use the `->onlyOnIndex()` accessor:
0 commit comments