vito/app/ValidationRules/CronRule.php
2025-03-12 13:31:10 +01:00

23 lines
563 B
PHP
Executable File

<?php
namespace App\ValidationRules;
use Cron\CronExpression;
use Illuminate\Contracts\Validation\ValidationRule;
class CronRule implements ValidationRule
{
public function __construct(private readonly bool $acceptCustom = false) {}
public function validate(string $attribute, mixed $value, \Closure $fail): void
{
if (CronExpression::isValidExpression($value)) {
return;
}
if ($this->acceptCustom && $value === 'custom') {
return;
}
$fail('Invalid frequency')->translate();
}
}