1 | <?php |
||
9 | abstract class BaseController |
||
10 | { |
||
11 | /** |
||
12 | * @var \Illuminate\Validation\Factory; |
||
13 | */ |
||
14 | public $validation; |
||
15 | |||
16 | /** |
||
17 | * @var \App\Common\JsonApiEncoder |
||
18 | */ |
||
19 | public $encoder; |
||
20 | |||
21 | /** |
||
22 | * @var \App\Common\ApiRenderer |
||
23 | */ |
||
24 | public $apiRenderer; |
||
25 | |||
26 | /** |
||
27 | * @var array |
||
28 | */ |
||
29 | public $settings; |
||
30 | |||
31 | /** |
||
32 | * @var \Swift_Mailer |
||
33 | */ |
||
34 | public $mailer; |
||
35 | |||
36 | /** |
||
37 | * @var \App\Common\MailRenderer |
||
38 | */ |
||
39 | public $mailRenderer; |
||
40 | |||
41 | /** |
||
42 | * BaseController constructor. |
||
43 | * |
||
44 | * @param $container |
||
45 | */ |
||
46 | public function __construct($container) |
||
57 | |||
58 | /** |
||
59 | * @param array|null|object $params |
||
60 | * @param string $entity |
||
61 | * @param IRequest $request |
||
62 | * |
||
63 | * @return bool |
||
64 | * @throws JsonException |
||
65 | */ |
||
66 | public function validateRequestParams($params, $entity, $request) |
||
67 | { |
||
68 | if (!isset($params['data']['attributes'])) { |
||
69 | throw new JsonException($entity, 400, 'Invalid Attribute', 'Do not see required attribute - data.'); |
||
70 | } |
||
71 | |||
72 | $validator = $this->validation->make($params['data']['attributes'], $request->rules()); |
||
73 | |||
74 | if ($validator->fails()) { |
||
75 | $messages = implode(' ', $validator->messages()->all()); |
||
76 | throw new JsonException($entity, 400, 'Invalid Attribute', $messages); |
||
77 | } |
||
78 | |||
79 | return true; |
||
80 | } |
||
81 | |||
82 | /** |
||
83 | * Register model observers |
||
84 | */ |
||
85 | private function registerModelObservers() |
||
107 | } |
||
108 |