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

PermissionRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 5
c 3
b 1
f 1
lcom 0
cbo 2
dl 0
loc 52
rs 10
ccs 0
cts 14
cp 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A rules() 0 11 1
A getMessages() 0 8 1
A getAttributes() 0 6 1
A withValidator() 0 6 1
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