| Conditions | 3 |
| Paths | 4 |
| Total Lines | 16 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| Changes | 0 | ||
| 1 | <?php |
||
| 15 | public function validate(array $values = [], $resource, $sometimes = false) |
||
| 16 | {
|
||
| 17 | $rules = $this->rules($resource); |
||
| 18 | $messages = $this->messages($resource); |
||
| 19 | $attributes = $this->attributes($resource); |
||
| 20 | $validator = Validator::make($values, $rules, $messages, $attributes); |
||
| 21 | if ($sometimes) {
|
||
| 22 | $extraRules = $this->rules('sometimes' . $resource);
|
||
| 23 | $validator->sometimes(array_keys($extraRules), $extraRules, function ($execution) use ($sometimes) {
|
||
| 24 | return $execution; |
||
| 25 | }); |
||
| 26 | } |
||
| 27 | if ($validator->fails()) {
|
||
| 28 | response()->json(['status' => 'failed', 'code' => 422, 'message' => $validator->errors()])->send(); |
||
| 29 | } |
||
| 30 | } |
||
| 31 | |||
| 46 | } |