File tree Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Expand file tree Collapse file tree 1 file changed +41
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace CloudCreativity \JsonApi \Http \Controllers ;
4
+
5
+ use CloudCreativity \JsonApi \Error \ThrowableError ;
6
+ use Illuminate \Support \Facades \Validator ;
7
+ use Neomerx \JsonApi \Contracts \Parameters \ParametersInterface ;
8
+
9
+ trait ValidatesParametersTrait
10
+ {
11
+
12
+ /**
13
+ * @return ParametersInterface
14
+ */
15
+ abstract public function getParameters ();
16
+
17
+ /**
18
+ * @param array $rules
19
+ * @param array $messages
20
+ * @param $errorMessage
21
+ * @return array
22
+ */
23
+ public function getUnrecognizedParameters (array $ rules = [], array $ messages = [], $ errorMessage = null )
24
+ {
25
+ $ params = (array ) $ this ->getParameters ()->getUnrecognizedParameters ();
26
+
27
+ if (empty ($ rules )) {
28
+ return $ params ;
29
+ }
30
+
31
+ /** @var \Illuminate\Contracts\Validation\Validator $validator */
32
+ $ validator = Validator::make ($ params , $ rules , $ messages );
33
+
34
+ if ($ validator ->fails ()) {
35
+ $ errorMessage = $ errorMessage ?: 'Invalid Query Parameters ' ;
36
+ throw new ThrowableError ($ errorMessage , 400 );
37
+ }
38
+
39
+ return $ params ;
40
+ }
41
+ }
You can’t perform that action at this time.
0 commit comments