1 | <?php |
||
13 | abstract class JsonApiController extends Controller |
||
14 | { |
||
15 | use JsonApiErrors; |
||
16 | |||
17 | /** |
||
18 | * Return the Eloquent Model for the resource. |
||
19 | * |
||
20 | * @return Model |
||
21 | */ |
||
22 | abstract protected function getModel(); |
||
23 | |||
24 | /** |
||
25 | * Return the type name of the resource. |
||
26 | * |
||
27 | * @return string |
||
28 | */ |
||
29 | protected function getModelType() |
||
33 | |||
34 | /** |
||
35 | * Return a listing of the resource. |
||
36 | * |
||
37 | * @param Request $request |
||
38 | * |
||
39 | * @return JsonApiResponse |
||
40 | */ |
||
41 | public function indexAction(Request $request) |
||
64 | |||
65 | /** |
||
66 | * Store a new record. |
||
67 | * |
||
68 | * @param Request $request |
||
69 | * |
||
70 | * @return JsonApiResponse |
||
71 | */ |
||
72 | public function storeAction(Request $request) |
||
78 | |||
79 | /** |
||
80 | * Return a specified record. |
||
81 | * |
||
82 | * @param Request $request |
||
83 | * @param Model|int $record |
||
84 | * |
||
85 | * @return JsonApiResponse |
||
86 | */ |
||
87 | public function showAction(Request $request, $record) |
||
94 | |||
95 | /** |
||
96 | * Update a specified record. |
||
97 | * |
||
98 | * @param Request $request |
||
99 | * @param Model|int $record |
||
100 | * |
||
101 | * @return JsonApiResponse |
||
102 | */ |
||
103 | public function updateAction(Request $request, $record) |
||
110 | |||
111 | /** |
||
112 | * Destroy a specified record. |
||
113 | * |
||
114 | * @param Request $request |
||
115 | * @param Model|int $record |
||
116 | * |
||
117 | * @return JsonApiResponse |
||
118 | */ |
||
119 | public function destroyAction(Request $request, $record) |
||
126 | |||
127 | /** |
||
128 | * Return an instance of the resource by primary key. |
||
129 | * |
||
130 | * @param int $key |
||
131 | * |
||
132 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
133 | * |
||
134 | * @return Model |
||
135 | */ |
||
136 | protected function findModelInstance($key) |
||
140 | |||
141 | /** |
||
142 | * Return any JSON API resource parameters from a request. |
||
143 | * |
||
144 | * @param Request $request |
||
145 | * |
||
146 | * @return array |
||
147 | */ |
||
148 | protected function getRequestParameters($request) |
||
157 | |||
158 | /** |
||
159 | * Return any comma separated values in a request query field as an array. |
||
160 | * |
||
161 | * @param Request $request |
||
162 | * @param string $key |
||
163 | * |
||
164 | * @return array |
||
165 | */ |
||
166 | protected function getRequestQuerySet($request, $key) |
||
170 | |||
171 | /** |
||
172 | * Transform a set of models into a JSON API collection. |
||
173 | * |
||
174 | * @param \Illuminate\Support\Collection $records |
||
175 | * @param array $fields |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | protected function transformCollection($records, array $fields = []) |
||
189 | |||
190 | /** |
||
191 | * Transform a model instance into a JSON API object. |
||
192 | * |
||
193 | * @param Model $record |
||
194 | * @param array|null $fields Field names of attributes to limit to |
||
195 | * @param array|null $include Relations to include |
||
196 | * |
||
197 | * @return array |
||
198 | */ |
||
199 | protected function transformRecord($record, array $fields = [], array $include = []) |
||
240 | } |
||
241 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.