Completed
Push — master ( 260d8b...dd8adc )
by wen
06:12
created

RoleRequest::rules()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 9.4285
cc 1
eloc 13
nc 1
nop 0
1
<?php
2
3
namespace Sco\Admin\Http\Requests;
4
5
use Illuminate\Validation\Rule;
6
7
class RoleRequest 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
            'name'         => [
29
                'bail',
30
                'required',
31
                'regex:/^[a-z0-9]+$/i',
32
                'max: 50',
33
                Rule::unique('roles')->ignore($this->input('id')),
34
            ],
35
            'display_name' => [
36
                'bail',
37
                'required',
38
                'alpha_num',
39
            ],
40
        ];
41
    }
42
43
    protected function getMessages()
44
    {
45
        return [
46
            'max' => trans('admin::validation.max.string'),
47
            'regex' => '字母数字',
48
        ];
49
    }
50
51
    protected function getAttributes()
52
    {
53
        return [
54
            'name' => '标识',
55
        ];
56
    }
57
}
58