1 | <?php |
||
22 | abstract class JsonApiController extends Controller |
||
23 | { |
||
24 | use JsonApiErrors; |
||
25 | use AuthorizesRequests; |
||
26 | use ValidatesRequests; |
||
27 | |||
28 | /** |
||
29 | * Return the Eloquent Model for the resource. |
||
30 | * |
||
31 | * @return Model |
||
32 | */ |
||
33 | abstract protected function getModel(); |
||
34 | |||
35 | /** |
||
36 | * The model relationships that can be updated. |
||
37 | * |
||
38 | * @return array |
||
39 | */ |
||
40 | protected function getModelRelationships() |
||
44 | |||
45 | /** |
||
46 | * Return a listing of the resource. |
||
47 | * |
||
48 | * @param Request $request |
||
49 | * @param \Illuminate\Database\Eloquent\Builder|null $query Custom resource query |
||
50 | * |
||
51 | * @return JsonApiResponse |
||
52 | */ |
||
53 | public function indexAction(Request $request, $query = null) |
||
72 | |||
73 | /** |
||
74 | * Store a new record. |
||
75 | * |
||
76 | * @param Request $request |
||
77 | * |
||
78 | * @return JsonApiResponse |
||
79 | */ |
||
80 | public function storeAction(Request $request) |
||
90 | |||
91 | /** |
||
92 | * Return a specified record. |
||
93 | * |
||
94 | * @param Request $request |
||
95 | * @param Model|int $record |
||
96 | * |
||
97 | * @return JsonApiResponse |
||
98 | */ |
||
99 | public function showAction(Request $request, $record) |
||
106 | |||
107 | /** |
||
108 | * Update a specified record. |
||
109 | * |
||
110 | * @param Request $request |
||
111 | * @param Model|int $record |
||
112 | * |
||
113 | * @return JsonApiResponse |
||
114 | */ |
||
115 | public function updateAction(Request $request, $record) |
||
127 | |||
128 | /** |
||
129 | * Destroy a specified record. |
||
130 | * |
||
131 | * @param Request $request |
||
132 | * @param Model|int $record |
||
133 | * |
||
134 | * @return JsonApiResponse |
||
135 | */ |
||
136 | public function destroyAction(Request $request, $record) |
||
143 | |||
144 | /** |
||
145 | * Return a specified record relationship. |
||
146 | * |
||
147 | * @param Request $request |
||
148 | * @param Model|int $record |
||
149 | * @param string $relation |
||
150 | * |
||
151 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
152 | * |
||
153 | * @return JsonApiResponse |
||
154 | */ |
||
155 | public function relationshipAction(Request $request, $record, $relation) |
||
163 | |||
164 | /** |
||
165 | * Update a named many-to-one relationship association on a specified record. |
||
166 | * http://jsonapi.org/format/#crud-updating-to-one-relationships |
||
167 | * |
||
168 | * @param Request $request |
||
169 | * @param Model|int $record |
||
170 | * @param string $relation |
||
171 | * |
||
172 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
173 | * |
||
174 | * @return JsonApiResponse |
||
175 | */ |
||
176 | public function updateToOneRelationshipAction(Request $request, $record, $relation) |
||
189 | |||
190 | /** |
||
191 | * Update named many-to-many relationship entries on a specified record. |
||
192 | * http://jsonapi.org/format/#crud-updating-to-many-relationships |
||
193 | * |
||
194 | * @param Request $request |
||
195 | * @param Model|int $record |
||
196 | * @param string $relation |
||
197 | * |
||
198 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
199 | * |
||
200 | * @return JsonApiResponse |
||
201 | */ |
||
202 | public function updateToManyRelationshipAction(Request $request, $record, $relation) |
||
231 | |||
232 | /** |
||
233 | * Return existing instance of the resource or find by primary key. |
||
234 | * |
||
235 | * @param Model|int $record |
||
236 | * |
||
237 | * @throws ModelNotFoundException |
||
238 | * |
||
239 | * @return Model |
||
240 | */ |
||
241 | protected function findModelInstance($record) |
||
253 | |||
254 | /** |
||
255 | * Return any JSON API resource parameters from a request. |
||
256 | * |
||
257 | * @param Request $request |
||
258 | * |
||
259 | * @return array |
||
260 | */ |
||
261 | protected function getRequestParameters($request) |
||
270 | |||
271 | /** |
||
272 | * Return any comma separated values in a request query field as an array. |
||
273 | * |
||
274 | * @param Request $request |
||
275 | * @param string $key |
||
276 | * |
||
277 | * @return array |
||
278 | */ |
||
279 | protected function getRequestQuerySet($request, $key) |
||
283 | |||
284 | /** |
||
285 | * Sort a resource query by one or more attributes. |
||
286 | * |
||
287 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
288 | * @param array $attributes |
||
289 | * |
||
290 | * @return \Illuminate\Database\Eloquent\Builder |
||
291 | */ |
||
292 | protected function sortQuery($query, $attributes) |
||
302 | |||
303 | /** |
||
304 | * Filter a resource query by one or more attributes. |
||
305 | * |
||
306 | * @param \Illuminate\Database\Eloquent\Builder $query |
||
307 | * @param array $attributes |
||
308 | * |
||
309 | * @return \Illuminate\Database\Eloquent\Builder |
||
310 | */ |
||
311 | protected function filterQuery($query, $attributes) |
||
334 | |||
335 | /** |
||
336 | * Update one or more relationships on a model instance. |
||
337 | * |
||
338 | * @param Model $record |
||
339 | * @param array $relationships |
||
340 | */ |
||
341 | protected function updateRecordRelationships($record, array $relationships) |
||
357 | } |
||
358 |
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: