| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?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
- */
- public function rules(): array
- {
- return [
- 'id' => 'nullable|exists:users',
- 'email' => 'required_if:id,null|unique:users,email,'.$this->id,
- 'name' => 'required|string|min:2',
- 'phone' => 'nullable|string',
- 'password' => 'required_without:id|nullable|string|min:4',
- 'role' => 'nullable|string|in:' . implode(',', Role::VALID_ROLES),
- 'color' => 'nullable|string',
- ];
- }
- public function messages(): array
- {
- return [
- 'name' => 'Поле обязательно для заполнения и должно быть не менее 2 символов!',
- 'password' => 'Пароль должен быть не менее 8 символов!',
- 'role' => 'Неправильная роль!',
- 'email' => 'Нужно указать адрес почты или логин, который не зарегистрирован в системе!',
- ];
- }
- }
|