2
2
3
3
## Introduction
4
4
5
- This package supports the [ inclusion of related resources] ( http://jsonapi.org/format/1.0/#fetching-includes ) .
5
+ This package supports the [ inclusion of related resources] ( http://jsonapi.org/format/1.0/#fetching-includes ) .
6
6
This allows a client to specify resources related to the primary data that should be included in the response.
7
7
The purpose is to allow the client to reduce the number of HTTP requests it needs to make to obtain all the data
8
8
it requires.
@@ -20,13 +20,13 @@ For this feature to work, you will need to:
20
20
default validators do not allow include paths.
21
21
2 . Add relationships to the resource [ Schema] ( ../basics/schemas.md ) and ensure they return data.
22
22
3 . For Eloquent models, define the translation of any JSON API include paths to eager load paths
23
- on the resource [ Adapter] ( ../basics/adapters.md ) .
23
+ on the resource [ Adapter] ( ../basics/adapters.md ) .
24
24
25
25
These are all described in this chapter.
26
26
27
27
## The Include Query Parameter
28
28
29
- Related resources are specified by the client using the ` include ` query parameter. This parameter
29
+ Related resources are specified by the client using the ` include ` query parameter. This parameter
30
30
contains a comma separated list of relationship paths that should be included. The response will be a
31
31
[ compound document] ( http://jsonapi.org/format/#document-compound-documents ) where the primary data of the
32
32
request is in the JSON's ` data ` member, and the related resources are in the ` included ` member.
@@ -37,7 +37,7 @@ resources in the same request:
37
37
``` http
38
38
GET /api/posts?include=author,tags HTTP/1.1
39
39
Accept: application/vnd.api+json
40
- ```
40
+ ```
41
41
42
42
If these include paths are valid, then the client will receive the following response:
43
43
@@ -79,7 +79,7 @@ Content-Type: application/vnd.api+json
79
79
"links": {
80
80
"self": "/api/posts/123/relationships/tags",
81
81
"related": "/api/posts/123/tags"
82
- }
82
+ }
83
83
}
84
84
},
85
85
"links": {
@@ -130,7 +130,7 @@ relationship, the client could request the following:
130
130
``` http
131
131
GET /api/posts?include=author.address,tags HTTP/1.1
132
132
Accept: application/vnd.api+json
133
- ```
133
+ ```
134
134
135
135
For this request, both the author ` users ` resource and the user's ` addresses ` resource would be present in
136
136
the ` included ` member of the JSON document.
@@ -201,7 +201,7 @@ class Validators extends AbstractValidators
201
201
'author.address',
202
202
'tags'
203
203
];
204
-
204
+
205
205
// ...
206
206
}
207
207
```
@@ -235,7 +235,7 @@ the posts schema would have to return both the related author and the related ta
235
235
``` php
236
236
namespace App\JsonApi\Posts;
237
237
238
- use Neomerx\JsonApi \Schema\SchemaProvider;
238
+ use CloudCreativity\LaravelJsonApi \Schema\SchemaProvider;
239
239
240
240
class Schema extends SchemaProvider
241
241
{
@@ -278,7 +278,7 @@ method on the `users` schema.
278
278
279
279
## Eager Loading
280
280
281
- The Eloquent adapter automatically converts JSON API include paths to Eloquent model
281
+ The Eloquent adapter automatically converts JSON API include paths to Eloquent model
282
282
[ eager loading] ( https://laravel.com/docs/eloquent-relationships#eager-loading ) paths.
283
283
The JSON API path is converted to a camel-case path. For example, the JSON API path
284
284
` author.current-address ` is converted to the ` author.currentAddress ` Eloquent path.
@@ -299,7 +299,7 @@ class Adapter extends AbstractAdapter
299
299
'author' => 'createdBy',
300
300
'author.current-address' => 'createdBy.currentAddress',
301
301
];
302
-
302
+
303
303
// ...
304
304
}
305
305
```
@@ -324,7 +324,7 @@ requested as primary data:
324
324
``` php
325
325
namespace App\JsonApi\Posts;
326
326
327
- use Neomerx\JsonApi \Schema\SchemaProvider;
327
+ use CloudCreativity\LaravelJsonApi \Schema\SchemaProvider;
328
328
329
329
class Schema extends SchemaProvider
330
330
{
@@ -344,7 +344,7 @@ This would mean that the following request receive a response with `users` and `
344
344
``` http
345
345
GET /api/posts HTTP/1.1
346
346
Accept: application/vnd.api+json
347
- ```
347
+ ```
348
348
349
349
### Default Path Eager Loading
350
350
@@ -359,7 +359,7 @@ use CloudCreativity\LaravelJsonApi\Eloquent\AbstractAdapter;
359
359
class Adapter extends AbstractAdapter
360
360
{
361
361
protected $defaultWith = ['author', 'tags'];
362
-
362
+
363
363
// ...
364
364
}
365
365
```
0 commit comments