Completed
Push — master ( 80411a...1281a7 )
by wen
03:35
created

UpdateUserRequest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 61
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A authorize() 0 4 1
A rules() 0 20 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
use Illuminate\Validation\Rule;
7
8
class UpdateUserRequest extends BaseFormRequest
9
{
10
    /**
11
     * Determine if the user is authorized to make this request.
12
     *
13
     * @return bool
14
     */
15
    public function authorize()
16
    {
17
        return true;
18
    }
19
20
    /**
21
     * Get the validation rules that apply to the request.
22
     *
23
     * @return array
24
     */
25
    public function rules()
26
    {
27
        return [
28
            'id'       => 'integer',
29
            'name'     => [
30
                'bail',
31
                'required',
32
                'regex:/^[a-z0-9]+$/i',
33
                'between:4,20',
34
                Rule::unique(config('admin.users_table'))->ignore($this->input('id')),
35
            ],
36
            'email'    => [
37
                'bail',
38
                'email',
39
                'required',
40
                Rule::unique(config('admin.users_table'))->ignore($this->input('id')),
41
            ],
42
            'password' => 'bail',
43
        ];
44
    }
45
46
    protected function getMessages()
47
    {
48
        return [
49
            'regex'   => '字母数字',
50
            'between' => trans('admin::validation.between.string'),
51
            'min'     => trans('admin::validation.min.string'),
52
        ];
53
    }
54
55
    protected function getAttributes()
56
    {
57
        return [
58
            'name' => '管理员名称',
59
        ];
60
    }
61
62
    protected function withValidator(Validator $validator)
63
    {
64
        $validator->sometimes('password', 'min:6', function () {
65
            return !empty($this->input('password'));
66
        });
67
    }
68
}
69