@php $client = auth('client')->user(); $canViewPhone = \App\Support\ImpersonatedClientPhone::canView($client); $profileCountry = (string) old('country', $client->country); $profileCity = (string) old('city', $client->city); $profileLocations = []; // Populate the country select in the HTML itself. It must not depend on // a second HTTP request (or an ASSET_URL / CDN) to show other countries. $profileLocationsPath = public_path('adm/json/countries.min.json'); if (is_readable($profileLocationsPath)) { try { $profileLocationsText = file_get_contents($profileLocationsPath); if ($profileLocationsText !== false) { $profileLocationRows = json_decode(preg_replace('/^\xEF\xBB\xBF/', '', $profileLocationsText), true, 512, JSON_THROW_ON_ERROR); foreach (is_array($profileLocationRows) ? $profileLocationRows : [] as $profileLocationRow) { if (!is_array($profileLocationRow) || !is_string($profileLocationRow['name'] ?? null)) { continue; } $profileLocationName = trim($profileLocationRow['name']); if ($profileLocationName === '') { continue; } $profileRegions = []; foreach (is_array($profileLocationRow['stateProvinces'] ?? null) ? $profileLocationRow['stateProvinces'] : [] as $profileRegion) { $profileRegionName = is_string($profileRegion) ? $profileRegion : (is_array($profileRegion) ? ($profileRegion['name'] ?? '') : ''); if (is_string($profileRegionName) && trim($profileRegionName) !== '') { $profileRegions[] = trim($profileRegionName); } } $profileLocations[$profileLocationName] = [ 'name' => $profileLocationName, 'countryCode' => (string) ($profileLocationRow['countryCode'] ?? ''), 'countryCodeAlpha3' => (string) ($profileLocationRow['countryCodeAlpha3'] ?? ''), // Keep only names, not flags, currencies or unused metadata. 'stateProvinces' => array_values(array_unique($profileRegions)), ]; } uasort($profileLocations, static fn (array $a, array $b) => strnatcasecmp($a['name'], $b['name'])); } } catch (\JsonException $exception) { // The picker retains the saved values and exposes its Retry action. \Illuminate\Support\Facades\Log::warning('The client profile location catalogue contains invalid JSON.'); } } $profileCountryKnown = false; foreach ($profileLocations as $profileLocation) { foreach (['name', 'countryCode', 'countryCodeAlpha3'] as $profileLocationKey) { $profileLocationValue = $profileLocation[$profileLocationKey]; if ($profileLocationValue !== '' && strcasecmp($profileLocationValue, trim($profileCountry)) === 0) { $profileCountry = $profileLocation['name']; $profileCountryKnown = true; break 2; } } } @endphp
Keep your contact details and location up to date.