added countries support expanded for ISO 3166 standard
This commit is contained in:
@@ -4,7 +4,6 @@ namespace Modules\Countries\Rules;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Validation\ValidationRule;
|
||||
use Modules\Countries\Models\Country;
|
||||
|
||||
class ValidCountryCode implements ValidationRule
|
||||
{
|
||||
@@ -14,19 +13,6 @@ class ValidCountryCode implements ValidationRule
|
||||
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void
|
||||
{
|
||||
if (! is_string($value) || strlen($value) !== 2) {
|
||||
$fail('The :attribute must be a valid ISO 3166 alpha-2 country code.');
|
||||
return;
|
||||
}
|
||||
|
||||
$query = Country::query()->where('alpha2', strtoupper($value));
|
||||
|
||||
if ($this->activeOnly) {
|
||||
$query->where('is_active', true);
|
||||
}
|
||||
|
||||
if (! $query->exists()) {
|
||||
$fail('The :attribute must be a supported country.');
|
||||
}
|
||||
(new ValidIso3166CountryCode($this->activeOnly, 'alpha2'))->validate($attribute, $value, $fail);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user