Просмотр файла app/Http/Requests/Invitation/StoreRequest.php

Размер файла: 927B
  1. <?php
  2.  
  3. namespace App\Http\Requests\Invitation;
  4.  
  5. use App\Models\Invite;
  6. use App\Services\InviteService;
  7. use Illuminate\Foundation\Http\FormRequest;
  8. use Illuminate\Validation\Validator;
  9.  
  10. class StoreRequest extends FormRequest
  11. {
  12. public function __construct(private InviteService $inviteService)
  13. {
  14. parent::__construct();
  15. }
  16.  
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array
  21. */
  22. public function rules()
  23. {
  24. return [
  25. '_token' => 'required|in:' . csrf_token(),
  26. ];
  27. }
  28.  
  29. public function withValidator(Validator $validator)
  30. {
  31. $lastInvite = $this->inviteService->getLastInviteByUserId(getUser('id'));
  32.  
  33. $validator->after(function ($validator) use ($lastInvite) {
  34. if ($lastInvite) {
  35. $validator->errors()->add('', __('invitations.limit_reached'));
  36. }
  37. });
  38. }
  39. }