%PDF- %PDF-
Direktori : /www/loslex/test/app/Rules/ |
Current File : /www/loslex/test/app/Rules/ContestPublication.php |
<?php namespace App\Rules; use Closure; use App\Enums\ContestLevelEnum; use App\Enums\ContestPublicationStatusEnum; use Illuminate\Contracts\Validation\DataAwareRule; use Illuminate\Contracts\Validation\ValidationRule; class ContestPublication 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 { if (!isset($this->data['contest_level_id'])) { return; } $level_cond = $this->data['contest_level_id'] == ContestLevelEnum::CUP->value || $this->data['contest_level_id'] == ContestLevelEnum::CHAMPIONSHIP->value || $this->data['contest_level_id'] == ContestLevelEnum::SZSCLASSIFICATION->value; $published_cond = $this->data['published'] == ContestPublicationStatusEnum::HIDDEN->value; if ($level_cond && $published_cond) { $fail('validation.contestpublication')->translate(); } } }