Completed
Push — master ( 1d6fcb...ffe307 )
by wen
05:09
created

PermissionRequest::withValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 0
loc 6
rs 9.4285
ccs 0
cts 0
cp 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Sco\Admin\Http\Requests;
4
5
use Illuminate\Contracts\Validation\Validator;
6
7
class PermissionRequest extends BaseFormRequest
8
{
9
    /**
10
     * Determine if the user is authorized to make this request.
11
     *
12
     * @return bool
13
     */
14
    public function authorize()
15
    {
16
        return true;
17
    }
18
19
    /**
20
     * Get the validation rules that apply to the request.
21
     *
22
     * @return array
23
     */
24
    public function rules()
25
    {
26
        return [
27
            'id'           => 'integer',
28
            'pid'          => 'integer',
29
            'display_name' => 'required|max:50',
30
            'name'         => ['bail', 'required', 'regex:/^[\w\.#]+$/'],
31
            'is_menu'      => 'in:0,1',
32
            'sort'         => 'integer|between:0,255',
33
        ];
34
    }
35
36
    protected function getMessages()
37
    {
38
        return [
39
            'max'      => trans('admin::validation.max.numeric'),
40
            'between'  => trans('admin::validation.between.numeric'),
41
            'different' => '所属父级不能是自己',
42
        ];
43
    }
44
45
    protected function getAttributes()
46
    {
47
        return [
48
            'name' => '菜单名称',
49
        ];
50
    }
51
52
    protected function withValidator(Validator $validator)
53
    {
54
        $validator->sometimes('pid', 'different:id', function () {
55
            return !empty($this->input('id'));
56
        });
57
    }
58
}
59