1 | <?php |
||
19 | abstract class JsonApiController extends Controller |
||
20 | { |
||
21 | use JsonApiErrors, JsonApiTransforms, AuthorizesRequests, ValidatesRequests; |
||
22 | |||
23 | /** |
||
24 | * Return the Eloquent Model for the resource. |
||
25 | * |
||
26 | * @return Model |
||
27 | */ |
||
28 | abstract protected function getModel(); |
||
29 | |||
30 | /** |
||
31 | * Return the type name of the resource. |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | protected function getModelType() |
||
39 | |||
40 | /** |
||
41 | * The model relationships that can be updated. |
||
42 | * |
||
43 | * @return string |
||
44 | */ |
||
45 | protected function getModelRelationships() |
||
49 | |||
50 | /** |
||
51 | * Return a listing of the resource. |
||
52 | * |
||
53 | * @param Request $request |
||
54 | * @param \Illuminate\Database\Eloquent\Builder|null $query Custom resource query |
||
55 | * |
||
56 | * @return JsonApiResponse |
||
57 | */ |
||
58 | public function indexAction(Request $request, $query = null) |
||
77 | |||
78 | /** |
||
79 | * Store a new record. |
||
80 | * |
||
81 | * @param Request $request |
||
82 | * |
||
83 | * @return JsonApiResponse |
||
84 | */ |
||
85 | public function storeAction(Request $request) |
||
95 | |||
96 | /** |
||
97 | * Return a specified record. |
||
98 | * |
||
99 | * @param Request $request |
||
100 | * @param Model|int $record |
||
101 | * |
||
102 | * @return JsonApiResponse |
||
103 | */ |
||
104 | public function showAction(Request $request, $record) |
||
111 | |||
112 | /** |
||
113 | * Update a specified record. |
||
114 | * |
||
115 | * @param Request $request |
||
116 | * @param Model|int $record |
||
117 | * |
||
118 | * @return JsonApiResponse |
||
119 | */ |
||
120 | public function updateAction(Request $request, $record) |
||
132 | |||
133 | /** |
||
134 | * Destroy a specified record. |
||
135 | * |
||
136 | * @param Request $request |
||
137 | * @param Model|int $record |
||
138 | * |
||
139 | * @return JsonApiResponse |
||
140 | */ |
||
141 | public function destroyAction(Request $request, $record) |
||
148 | |||
149 | /** |
||
150 | * Return a specified record relationship. |
||
151 | * |
||
152 | * @param Request $request |
||
153 | * @param Model|int $record |
||
154 | * @param string $relation |
||
155 | * |
||
156 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
157 | * |
||
158 | * @return JsonApiResponse |
||
159 | */ |
||
160 | public function relationshipAction(Request $request, $record, $relation) |
||
168 | |||
169 | /** |
||
170 | * Update a named many-to-one relationship association on a specified record. |
||
171 | * http://jsonapi.org/format/#crud-updating-to-one-relationships |
||
172 | * |
||
173 | * @param Request $request |
||
174 | * @param Model|int $record |
||
175 | * @param string $relation |
||
176 | * |
||
177 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
178 | * |
||
179 | * @return JsonApiResponse |
||
180 | */ |
||
181 | public function updateToOneRelationshipAction(Request $request, $record, $relation) |
||
194 | |||
195 | /** |
||
196 | * Update named many-to-many relationship entries on a specified record. |
||
197 | * http://jsonapi.org/format/#crud-updating-to-many-relationships |
||
198 | * |
||
199 | * @param Request $request |
||
200 | * @param Model|int $record |
||
201 | * @param string $relation |
||
202 | * |
||
203 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
204 | * |
||
205 | * @return JsonApiResponse |
||
206 | */ |
||
207 | public function updateToManyRelationshipAction(Request $request, $record, $relation) |
||
236 | |||
237 | /** |
||
238 | * Return existing instance of the resource or find by primary key. |
||
239 | * |
||
240 | * @param Model|int $record |
||
241 | * |
||
242 | * @throws ModelNotFoundException |
||
243 | * |
||
244 | * @return Model |
||
245 | */ |
||
246 | protected function findModelInstance($record) |
||
258 | |||
259 | /** |
||
260 | * Return any JSON API resource parameters from a request. |
||
261 | * |
||
262 | * @param Request $request |
||
263 | * |
||
264 | * @return array |
||
265 | */ |
||
266 | protected function getRequestParameters($request) |
||
275 | |||
276 | /** |
||
277 | * Return any comma separated values in a request query field as an array. |
||
278 | * |
||
279 | * @param Request $request |
||
280 | * @param string $key |
||
281 | * |
||
282 | * @return array |
||
283 | */ |
||
284 | protected function getRequestQuerySet($request, $key) |
||
288 | |||
289 | /** |
||
290 | * Sort a resource query by one or more attributes. |
||
291 | * |
||
292 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
293 | * @param array $attributes |
||
294 | * |
||
295 | * @return \Illuminate\Database\Eloquent\Builder |
||
296 | */ |
||
297 | protected function sortQuery($query, $attributes) |
||
307 | |||
308 | /** |
||
309 | * Filter a resource query by one or more attributes. |
||
310 | * |
||
311 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
312 | * @param array $attributes |
||
313 | * |
||
314 | * @return \Illuminate\Database\Eloquent\Builder |
||
315 | */ |
||
316 | protected function filterQuery($query, $attributes) |
||
333 | |||
334 | /** |
||
335 | * Update one or more relationships on a model instance. |
||
336 | * |
||
337 | * @param Model $record |
||
338 | * @param array $relationships |
||
339 | */ |
||
340 | protected function updateRecordRelationships($record, array $relationships) |
||
356 | } |
||
357 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: