1 | <?php |
||
26 | abstract class JsonApiController extends Controller |
||
27 | { |
||
28 | use JsonApiErrors; |
||
29 | use QueriesResources; |
||
30 | use UpdatesModelRelations; |
||
31 | use AuthorizesRequests; |
||
32 | use ValidatesRequests; |
||
33 | |||
34 | /** |
||
35 | * The Eloquent Model for the resource. |
||
36 | * |
||
37 | * @var Model|string |
||
38 | */ |
||
39 | protected $model; |
||
40 | |||
41 | /** |
||
42 | * Create a new JsonApiController instance. |
||
43 | */ |
||
44 | public function __construct() |
||
55 | |||
56 | /** |
||
57 | * Return a listing of the resource. |
||
58 | * |
||
59 | * @param Request $request |
||
60 | * @param \Illuminate\Database\Eloquent\Builder|null $query Custom resource query |
||
61 | * |
||
62 | * @return JsonApiResponse |
||
63 | */ |
||
64 | public function indexAction(Request $request, $query = null) |
||
84 | |||
85 | /** |
||
86 | * Store a new record. |
||
87 | * |
||
88 | * @param Request $request |
||
89 | * |
||
90 | * @return JsonApiResponse |
||
91 | */ |
||
92 | public function storeAction(Request $request) |
||
102 | |||
103 | /** |
||
104 | * Return a specified record. |
||
105 | * |
||
106 | * @param Request $request |
||
107 | * @param Model|mixed $record |
||
108 | * |
||
109 | * @return JsonApiResponse |
||
110 | */ |
||
111 | public function showAction(Request $request, $record) |
||
119 | |||
120 | /** |
||
121 | * Update a specified record. |
||
122 | * |
||
123 | * @param Request $request |
||
124 | * @param Model|mixed $record |
||
125 | * |
||
126 | * @return JsonApiResponse |
||
127 | */ |
||
128 | public function updateAction(Request $request, $record) |
||
140 | |||
141 | /** |
||
142 | * Destroy a specified record. |
||
143 | * |
||
144 | * @param Request $request |
||
145 | * @param Model|mixed $record |
||
146 | * |
||
147 | * @return JsonApiResponse |
||
148 | */ |
||
149 | public function destroyAction(Request $request, $record) |
||
156 | |||
157 | /** |
||
158 | * Return a specified record relationship. |
||
159 | * |
||
160 | * @param Request $request |
||
161 | * @param Model|mixed $record |
||
162 | * @param string $relation |
||
163 | * |
||
164 | * @return JsonApiResponse |
||
165 | */ |
||
166 | public function showRelationshipAction(Request $request, $record, $relation) |
||
167 | { |
||
168 | $record = $this->findModelInstance($record); |
||
169 | |||
170 | return new JsonApiResponse(new RelationshipSerializer($record, $relation)); |
||
171 | } |
||
172 | |||
173 | /** |
||
174 | * Update a named many-to-one relationship association on a specified record. |
||
175 | * http://jsonapi.org/format/#crud-updating-to-one-relationships |
||
176 | * |
||
177 | * @param Request $request |
||
178 | * @param Model|mixed $record |
||
179 | * @param string $relation |
||
180 | * |
||
181 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
182 | * |
||
183 | * @return JsonApiResponse |
||
184 | */ |
||
185 | public function updateToOneRelationshipAction(Request $request, $record, $relation) |
||
198 | |||
199 | /** |
||
200 | * Update named many-to-many relationship entries on a specified record. |
||
201 | * http://jsonapi.org/format/#crud-updating-to-many-relationships |
||
202 | * |
||
203 | * @param Request $request |
||
204 | * @param Model|mixed $record |
||
205 | * @param string $relation |
||
206 | * |
||
207 | * @throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException |
||
208 | * |
||
209 | * @return JsonApiResponse |
||
210 | */ |
||
211 | public function updateToManyRelationshipAction(Request $request, $record, $relation) |
||
240 | |||
241 | /** |
||
242 | * Return existing instance of the resource or find by primary key. |
||
243 | * |
||
244 | * @param Model|mixed $record |
||
245 | * |
||
246 | * @throws ModelNotFoundException |
||
247 | * |
||
248 | * @return Model |
||
249 | */ |
||
250 | protected function findModelInstance($record) |
||
262 | |||
263 | /** |
||
264 | * Return any JSON API resource parameters from a request. |
||
265 | * |
||
266 | * @param Request $request |
||
267 | * |
||
268 | * @return array |
||
269 | */ |
||
270 | protected function getRequestParameters($request) |
||
285 | |||
286 | /** |
||
287 | * Return any comma separated values in a request query field as an array. |
||
288 | * |
||
289 | * @param Request $request |
||
290 | * @param string $key |
||
291 | * @param string|null $validate Regular expression to test for each item |
||
292 | * |
||
293 | * @throws \Illuminate\Validation\ValidationException |
||
294 | * |
||
295 | * @return array |
||
296 | */ |
||
297 | protected function getRequestQuerySet($request, $key, $validate = null) |
||
314 | |||
315 | /** |
||
316 | * Validate the requested included relationships against those that are |
||
317 | * allowed on the requested resource type. |
||
318 | * |
||
319 | * @param array|null $relations |
||
320 | * |
||
321 | * @throws InvalidRelationPathException |
||
322 | */ |
||
323 | protected function validateIncludableRelations($relations) |
||
335 | } |
||
336 |
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: