Passed
Push — master ( ab23d3...456c2a )
by Ferry
05:06
created

Validation::validation()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 8
rs 10
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: User
5
 * Date: 8/15/2019
6
 * Time: 11:44 PM
7
 */
8
9
namespace crocodicstudio\crudbooster\controllers\traits;
10
11
use Illuminate\Support\Facades\Validator;
12
use crocodicstudio\crudbooster\exceptions\CBValidationException;
13
14
trait Validation
15
{
16
17
    /**
18
     * @throws CBValidationException
19
     */
20
    private function validation()
21
    {
22
        if(isset($this->data['validation'])) {
23
            $validator = Validator::make(request()->all(), @$this->data['validation'], @$this->data['validation_messages']);
24
            if ($validator->fails()) {
25
                $message = $validator->messages();
26
                $message_all = $message->all();
27
                throw new CBValidationException(implode(', ',$message_all));
28
            }
29
        }
30
    }
31
32
}