%PDF- %PDF-
| Direktori : /www/loslex_o/demo/app/Rules/ |
| Current File : /www/loslex_o/demo/app/Rules/ContestRegistrationEnd.php |
<?php
namespace App\Rules;
use Closure;
use Carbon\Carbon;
use Carbon\CarbonInterval;
use Illuminate\Contracts\Validation\DataAwareRule;
use Illuminate\Contracts\Validation\ValidationRule;
class ContestRegistrationEnd implements DataAwareRule, ValidationRule
{
/**
* All of the data under validation.
* @var array<string, mixed>
*/
protected $data = [];
/**
* Set the data under validation.
* @param array<string, mixed> $data
*/
public function setData(array $data): static
{
$this->data = $data;
return $this;
}
/**
* Run the validation rule.
*
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
*/
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$contestStart = new Carbon($this->data['date']);
$contestStart->add(CarbonInterval::createFromFormat('H:i', $this->data['presentation_start'][0] ?? $this->data['presentation_start'][1]));
$regEndDateTime = new Carbon($value);
if ($regEndDateTime->gte($contestStart)) {
$fail('validation.contestregend')->translate();
}
}
}