toby/app/Domain/Validation/Rules/NoPendingVacationRequestInRange.php
Adrian Hopek d825dd727f
#63 - permissions (#67)
* wip

* fix

* wip

* #63 - permissions

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
2022-03-02 09:52:50 +01:00

27 lines
667 B
PHP

<?php
declare(strict_types=1);
namespace Toby\Domain\Validation\Rules;
use Toby\Domain\VacationRequestStatesRetriever;
use Toby\Eloquent\Models\VacationRequest;
class NoPendingVacationRequestInRange implements VacationRequestRule
{
public function check(VacationRequest $vacationRequest): bool
{
return !$vacationRequest
->user
->vacationRequests()
->overlapsWith($vacationRequest)
->states(VacationRequestStatesRetriever::pendingStates())
->exists();
}
public function errorMessage(): string
{
return __("You have pending vacation request in this range.");
}
}