Skip to content

Commit 549f087

Browse files
authored
Merge pull request #11677 from nanaya/user-country-check
Always check for user country presence when saving
2 parents 3efdafb + 8bbd172 commit 549f087

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

app/Models/User.php

+6-11
Original file line numberDiff line numberDiff line change
@@ -2318,17 +2318,12 @@ public function isValid()
23182318
$this->isValidEmail();
23192319
}
23202320

2321-
if ($this->isDirty('country_acronym')) {
2322-
if (present($this->country_acronym)) {
2323-
$country = app('countries')->byCode($this->country_acronym);
2324-
if ($country === null) {
2325-
$this->validationErrors()->add('country', '.invalid_country');
2326-
} else {
2327-
// ensure matching case
2328-
$this->country_acronym = $country->getKey();
2329-
}
2330-
} else {
2331-
$this->country_acronym = Country::UNKNOWN;
2321+
$countryAcronym = $this->country_acronym;
2322+
if ($countryAcronym === null) {
2323+
$this->country_acronym = Country::UNKNOWN;
2324+
} elseif ($this->isDirty('country_acronym') && $countryAcronym !== Country::UNKNOWN) {
2325+
if (app('countries')->byCode($countryAcronym) === null) {
2326+
$this->validationErrors()->add('country', '.invalid_country');
23322327
}
23332328
}
23342329

0 commit comments

Comments
 (0)