File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change @@ -144,3 +144,44 @@ public function delete(RequestInterface $request)
144
144
return $this->reply()->noContent();
145
145
}
146
146
```
147
+
148
+ ## Relationship
149
+ If you have defined relationships in the schema of a resource, you would then need to state the following in your controller too:
150
+
151
+ 1 . ` readRelatedResource() `
152
+ 2 . ` readRelationship() `
153
+
154
+ ### Read Related Resource
155
+ If you link one resource to another through relationship, you'll need this to read the related resource.
156
+
157
+ ``` php
158
+ /**
159
+ * @param JsonApiRequest $request
160
+ * @return mixed
161
+ */
162
+ public function readRelatedResource(JsonApiRequest $request)
163
+ {
164
+ $model = $request->getRecord();
165
+ $key = $request->getRelationshipName();
166
+ return $this
167
+ ->reply()
168
+ ->content($model->{$key});
169
+ }
170
+ ```
171
+
172
+ ### Read Relationship
173
+ This is for reading the relationship between two resources.
174
+ ``` php
175
+ /**
176
+ * @param JsonApiRequest $request
177
+ * @return mixed
178
+ */
179
+ public function readRelationship(JsonApiRequest $request)
180
+ {
181
+ $model = $request->getRecord();
182
+ $key = $request->getRelationshipName();
183
+ return $this
184
+ ->reply()
185
+ ->relationship($model->{$key});
186
+ }
187
+ ```
You can’t perform that action at this time.
0 commit comments