| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Http\Requests\User;
- use App\Models\Role;
- use Illuminate\Foundation\Http\FormRequest;
- class StoreUser extends FormRequest
- {
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- return hasRole('admin');
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
- */
- public function rules(): array
- {
- return [
- 'id' => 'nullable|exists:users',
- 'email' => 'required_if:id,null|email|unique:users,email,'.$this->id,
- 'name' => 'required|string|min:2',
- 'password' => 'required_without:id|nullable|string|min:4',
- 'role' => 'nullable|string|in:' . implode(',', Role::VALID_ROLES),
- ];
- }
- public function messages(): array
- {
- return [
- 'name' => 'Поле обязательно для заполнения и должно быть не менее 2 символов!',
- 'password' => 'Пароль должен быть не менее 8 символов!',
- 'role' => 'Неправильная роль!',
- 'email' => 'Нужно указать правильный адрес почты, который не зарегистрирован в системе!',
- ];
- }
- }
|