Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| StoreUserRequest | |
0.00% |
0 / 27 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| authorize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| prepareForValidation | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
6 | |||
| rules | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| attributes | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Requests\Bo\Users; |
| 4 | |
| 5 | use App\Enums\Users\RoleEnum; |
| 6 | use Illuminate\Foundation\Http\FormRequest; |
| 7 | use Illuminate\Validation\Rules\Enum; |
| 8 | use Illuminate\Validation\Rules\Password; |
| 9 | |
| 10 | class StoreUserRequest extends FormRequest |
| 11 | { |
| 12 | /** |
| 13 | * Determine if the user is authorized to make this request. |
| 14 | * |
| 15 | * @return boolean |
| 16 | */ |
| 17 | public function authorize(): bool |
| 18 | { |
| 19 | return auth('backend')->check(); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Prepare the data for validation. |
| 24 | * |
| 25 | * @return void |
| 26 | */ |
| 27 | protected function prepareForValidation() |
| 28 | { |
| 29 | $this->merge([ |
| 30 | 'published' => $this->published ? true : false |
| 31 | ]); |
| 32 | } |
| 33 | |
| 34 | /** |
| 35 | * Get the validation rules that apply to the request. |
| 36 | * |
| 37 | * @return array |
| 38 | */ |
| 39 | public function rules(): array |
| 40 | { |
| 41 | return [ |
| 42 | 'first_name' => 'required|string|min:3|max:255', |
| 43 | 'last_name' => 'required|string|min:3|max:255', |
| 44 | 'email' => 'required|email:rfc,strict,dns,spoof,filter|unique:users,email', |
| 45 | 'password' => [ |
| 46 | 'required', 'required_with:password_confirmation', 'confirmed', 'max:255', Password::min(8) |
| 47 | ->letters() |
| 48 | ->mixedCase() |
| 49 | ->numbers() |
| 50 | ->symbols() |
| 51 | ->uncompromised() |
| 52 | ], |
| 53 | 'role' => ['required', new Enum(RoleEnum::class)], |
| 54 | 'published' => 'required|boolean', |
| 55 | ]; |
| 56 | } |
| 57 | |
| 58 | /** |
| 59 | * Get custom attributes for validator errors. |
| 60 | * |
| 61 | * @return array |
| 62 | */ |
| 63 | public function attributes(): array |
| 64 | { |
| 65 | return [ |
| 66 | 'first_name' => trans('validation.attributes.first_name'), |
| 67 | 'last_name' => trans('validation.attributes.last_name'), |
| 68 | 'email' => trans('validation.attributes.email'), |
| 69 | 'password' => trans('validation.attributes.password'), |
| 70 | 'role' => trans('validation.attributes.role'), |
| 71 | 'published' => trans('validation.custom.publication') |
| 72 | ]; |
| 73 | } |
| 74 | } |