1 | <?php |
||
8 | class RelationshipSerializer extends JsonApiSerializer |
||
9 | { |
||
10 | /** |
||
11 | * The loaded relation to transform. |
||
12 | * |
||
13 | * @var Collection|Model|null |
||
14 | */ |
||
15 | protected $relation; |
||
16 | |||
17 | /** |
||
18 | * The subset of attributes to return on each included record type. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $fields; |
||
23 | |||
24 | /** |
||
25 | * Create a new JSON API relationship serializer. |
||
26 | * |
||
27 | * @param Model $record The primary record |
||
28 | * @param string $relation The named relation to serialize |
||
29 | * @param array|null $fields Subset of fields to return by record type |
||
30 | */ |
||
31 | public function __construct($record, $relation, array $fields = []) |
||
38 | |||
39 | /** |
||
40 | * Return a JSON API resource linkage representation, composed of a |
||
41 | * resource identifier for each related record. |
||
42 | * |
||
43 | * @return Collection|array|null |
||
44 | */ |
||
45 | public function toResourceLinkage() |
||
51 | |||
52 | /** |
||
53 | * Return a single, or collection of, JSON API resource objects for each |
||
54 | * record in the relationship. |
||
55 | * |
||
56 | * @return Collection|array|null |
||
57 | */ |
||
58 | public function toResourceCollection() |
||
64 | |||
65 | /** |
||
66 | * Return primary data for the JSON API document. |
||
67 | * |
||
68 | * @return mixed |
||
69 | */ |
||
70 | protected function getPrimaryData() |
||
74 | |||
75 | /** |
||
76 | * Run a map over each item in the relationship. |
||
77 | * |
||
78 | * @param \Closure $callback |
||
79 | * |
||
80 | * @return mixed |
||
81 | */ |
||
82 | protected function map($callback) |
||
92 | } |
||
93 |