StoreUser.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace App\Http\Requests\User;
  3. use App\Models\Role;
  4. use App\Models\Reclamation;
  5. use App\Models\Order;
  6. use Illuminate\Foundation\Http\FormRequest;
  7. class StoreUser extends FormRequest
  8. {
  9. /**
  10. * Determine if the user is authorized to make this request.
  11. */
  12. public function authorize(): bool
  13. {
  14. return hasRole('admin');
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function rules(): array
  22. {
  23. return [
  24. 'id' => 'nullable|exists:users',
  25. 'email' => 'required_if:id,null|unique:users,email,'.$this->id,
  26. 'name' => 'required|string|min:2',
  27. 'phone' => 'nullable|string',
  28. 'password' => 'required_without:id|nullable|string|min:4',
  29. 'role' => 'nullable|string|in:' . implode(',', Role::VALID_ROLES),
  30. 'color' => 'nullable|string',
  31. 'notification_email' => 'nullable|email',
  32. 'notification_settings' => 'nullable|array',
  33. ];
  34. }
  35. public function messages(): array
  36. {
  37. return [
  38. 'name' => 'Поле обязательно для заполнения и должно быть не менее 2 символов!',
  39. 'password' => 'Пароль должен быть не менее 8 символов!',
  40. 'role' => 'Неправильная роль!',
  41. 'email' => 'Нужно указать адрес почты или логин, который не зарегистрирован в системе!',
  42. ];
  43. }
  44. }