| Total Complexity | 6 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 9 | class AdminUserRequest extends FormRequest |
||
| 10 | { |
||
| 11 | /** |
||
| 12 | * Determine if the user is authorized to make this request. |
||
| 13 | * |
||
| 14 | * @return bool |
||
| 15 | */ |
||
| 16 | public function authorize() |
||
| 19 | } |
||
| 20 | |||
| 21 | /** |
||
| 22 | * Get the validation rules that apply to the request. |
||
| 23 | * |
||
| 24 | * @return array |
||
| 25 | */ |
||
| 26 | public function rules() |
||
| 27 | { |
||
| 28 | $status_in = [ |
||
| 29 | AdminUser::STATUS_DISABLE, |
||
| 30 | AdminUser::STATUS_ENABLE, |
||
| 31 | ]; |
||
| 32 | |||
| 33 | $passwordRule = ''; |
||
| 34 | if ($this->method() == 'POST' || |
||
| 35 | ($this->method() == 'PUT' && request()->post('password') !== '')) { |
||
| 36 | $passwordRule = [ |
||
| 37 | 'required', |
||
| 38 | 'regex:/^(?![0-9]+$)(?![a-zA-Z]+$)[\w\x21-\x7e]{6,18}$/' |
||
| 39 | ]; |
||
| 40 | } |
||
| 41 | return [ |
||
| 42 | 'name' => 'required|max:50', |
||
| 43 | 'password' => $passwordRule, |
||
| 44 | 'status' => [ |
||
| 45 | Rule::in($status_in), |
||
| 46 | ], |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Get custom messages for validator errors. |
||
| 52 | * |
||
| 53 | * @return array |
||
| 54 | */ |
||
| 55 | public function messages() |
||
| 61 | ]; |
||
| 62 | } |
||
| 64 |