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
For the relationships to be included they need to be loaded. This can be done by implementing a `?include` parameter or using [spatie/laravel-query-builder](https://spatie.be/docs/laravel-query-builder/v3/introduction).
71
+
72
+
## Resource depth
73
+
74
+
The resource depth has a default of 2. This can be changed by passing an array to the resource where the second item is the required resource depth.
75
+
In the following example we use a depth of 3:
76
+
77
+
```php
78
+
public function show(ShowCourseRequest $request, Course $course)
79
+
{
80
+
$query = (new CoursesQueryBuilder)->find($course->id);
81
+
return new CourseResource([$query, 3]);
82
+
}
83
+
```
84
+
85
+
Which allows us to ask for an include nested 3 levels deep: `/courses/{identifier}?include=content,content.answers,content.answers.feedback`
86
+
87
+
## Exception handler
88
+
89
+
This package contains an exception handler to render exceptions as JSON:API error messages.
90
+
Either use this handler directly by editing your `app.php` and registering this singleton
For the relationships to be included they need to be loaded. This can be done by implementing a `?include` parameter or using [spatie/laravel-query-builder](https://spatie.be/docs/laravel-query-builder/v3/introduction).
105
-
106
254
## Tweak response
255
+
107
256
The `register` method doesn't have access to `$request` like `toArray` of `JsonResource` has.
108
257
If you want to manipulate the response based on the request this can be done by overriding the `addToResponse` method.
109
258
@@ -118,71 +267,8 @@ protected function addToResponse($request, $response): array
118
267
119
268
return $response;
120
269
}
121
-
````
122
-
123
-
## Resource depth
124
-
The resource depth has a default of 2. This can be changed by passing an array to the resource where the second item is the required resource depth.
125
-
In the following example we use a depth of 3:
126
-
127
-
```php
128
-
public function show(ShowCourseRequest $request, Course $course)
129
-
{
130
-
$query = (new CoursesQueryBuilder)->find($course->id);
131
-
return new CourseResource([$query, 3]);
132
-
}
133
-
```
134
-
135
-
Which allows us to ask for an include nested 3 levels deep: `/courses/{identifier}?include=content,content.answers,content.answers.feedback`
136
-
137
-
## Exception handler
138
-
This package contains an exception handler to render exceptions as JSON:API error messages.
139
-
Either use this handler directly by editing your `app.php` and registering this singleton
0 commit comments