toby/app/Domain/Validation/Rules/NoApprovedVacationRequestsInRange.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
670 B
PHP

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