final class SameYearAs implements ValidationRule
{
public function __construct(private mixed $toCompareWith)
{}
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$toCompareWith = $this->toCompareWith;
if (filled($toCompareWith)) {
$value = CarbonImmutable::parse($value);
$toCompareWith = CarbonImmutable::parse($toCompareWith);
if (!$value->isSameYear($toCompareWith)) {
$fail('Not similar year!');
}
}
}
}
final class SameYearAs implements ValidationRule
{
public function __construct(private mixed $toCompareWith)
{}
public function validate(string $attribute, mixed $value, Closure $fail): void
{
$toCompareWith = $this->toCompareWith;
if (filled($toCompareWith)) {
$value = CarbonImmutable::parse($value);
$toCompareWith = CarbonImmutable::parse($toCompareWith);
if (!$value->isSameYear($toCompareWith)) {
$fail('Not similar year!');
}
}
}
}