2026-03-29 20:26:27 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Rules;
|
|
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
2026-03-29 22:24:28 +00:00
|
|
|
use Illuminate\Translation\PotentiallyTranslatedString;
|
2026-03-29 20:26:27 +00:00
|
|
|
|
|
|
|
|
class Timezone implements ValidationRule
|
|
|
|
|
{
|
|
|
|
|
/**
|
2026-03-29 22:24:28 +00:00
|
|
|
* @param Closure(string, ?string=): PotentiallyTranslatedString $fail
|
2026-03-29 20:26:27 +00:00
|
|
|
*/
|
|
|
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
new \DateTimeZone($value);
|
|
|
|
|
} catch (\Exception) {
|
|
|
|
|
$fail('The :attribute must be a valid timezone.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|