23 lines
536 B
PHP
23 lines
536 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Rules;
|
|
|
|
use Closure;
|
|
use Illuminate\Contracts\Validation\ValidationRule;
|
|
|
|
class Timezone implements ValidationRule
|
|
{
|
|
/**
|
|
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
|
*/
|
|
public function validate(string $attribute, mixed $value, Closure $fail): void
|
|
{
|
|
try {
|
|
new \DateTimeZone($value);
|
|
} catch (\Exception) {
|
|
$fail('The :attribute must be a valid timezone.');
|
|
}
|
|
}
|
|
}
|