1 | <?php |
||
11 | abstract class JsonApiController extends Controller |
||
12 | { |
||
13 | use JsonApiErrors; |
||
14 | |||
15 | /** |
||
16 | * Return the Eloquent Model for the resource. |
||
17 | * |
||
18 | * @return Model |
||
19 | */ |
||
20 | abstract protected function getModel(); |
||
21 | |||
22 | /** |
||
23 | * Return the type name of the resource. |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | protected function getModelType() |
||
31 | |||
32 | /** |
||
33 | * Return a listing of the resource. |
||
34 | * |
||
35 | * @param Request $request |
||
36 | * |
||
37 | * @return JsonApiResponse |
||
38 | */ |
||
39 | public function indexAction(Request $request) |
||
47 | |||
48 | /** |
||
49 | * Return a specified record. |
||
50 | * |
||
51 | * @param Request $request |
||
52 | * @param Model|int $record |
||
53 | * |
||
54 | * @return JsonApiResponse |
||
55 | */ |
||
56 | public function showAction(Request $request, $record) |
||
64 | |||
65 | /** |
||
66 | * Return an instance of the resource by primary key. |
||
67 | * |
||
68 | * @param int $key |
||
69 | * |
||
70 | * @throws \Illuminate\Database\Eloquent\ModelNotFoundException |
||
71 | * |
||
72 | * @return Model |
||
73 | */ |
||
74 | protected function findModelInstance($key) |
||
78 | |||
79 | /** |
||
80 | * Return any JSON API resource parameters from a request. |
||
81 | * |
||
82 | * @param Request $request |
||
83 | * |
||
84 | * @return array |
||
85 | */ |
||
86 | protected function getRequestParameters($request) |
||
93 | |||
94 | /** |
||
95 | * Return any comma separated values in a request query field as an array. |
||
96 | * |
||
97 | * @param Request $request |
||
98 | * @param string $key |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | protected function getRequestQuerySet($request, $key) |
||
106 | |||
107 | /** |
||
108 | * Transform a set of models into a JSON API collection. |
||
109 | * |
||
110 | * @param \Illuminate\Support\Collection $records |
||
111 | * @param array $fields |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | protected function transformCollection($records, array $fields = []) |
||
125 | |||
126 | /** |
||
127 | * Transform a model instance into a JSON API object. |
||
128 | * |
||
129 | * @param Model $record |
||
130 | * @param array|null $fields Field names of attributes to limit to |
||
131 | * @param array|null $include Relations to include |
||
132 | * |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function transformRecord($record, array $fields = [], array $include = []) |
||
179 | } |
||
180 |