{{-- Currency dropdown mapping each supported country to its currency. Only include this once per page — element ids are fixed, not namespaced per instance. Country/currency list comes from Modules\DigitalMenu\Support\Countries — add a country there and make sure a matching row (by ISO code) exists in the `currencies` table (see database/migrations/2026_07_31_000100_add_world_currencies.php). Usage: @include('digitalmenu::partials.currency_selector', [ 'fieldName' => 'currency_id', // optional, defaults to 'currency_id' 'selectedId' => old('currency_id', $shop->currency_id), 'currencyError' => $errors->has('currency_id'), // optional ]) --}} @php $currencyIdsByCode = \Modules\DigitalMenu\Entities\Currency::whereIn('symbol', array_keys(\Modules\DigitalMenu\Support\Countries::currencies())) ->pluck('id', 'symbol'); // Multiple countries can share a currency (USD, EUR, XOF…). Prefer the currency's // home country (e.g. United States for USD) over whichever one appears first — // detected by the currency code starting with the country's ISO code (USD -> US). $byCurrency = []; foreach (\Modules\DigitalMenu\Support\Countries::all() as $country) { if (!isset($currencyIdsByCode[$country['currency']])) { continue; } $isHomeCountry = strpos($country['currency'], $country['code']) === 0; if (!isset($byCurrency[$country['currency']]) || $isHomeCountry) { $country['id'] = (int) $currencyIdsByCode[$country['currency']]; $byCurrency[$country['currency']] = $country; } } $currencyOptions = array_values($byCurrency); $fieldName = $fieldName ?? 'currency_id'; $selectedId = (int) ($selectedId ?? old($fieldName)); $currencyError = $currencyError ?? $errors->has($fieldName); $selectedCurrency = null; foreach ($currencyOptions as $country) { if ($country['id'] === $selectedId) { $selectedCurrency = $country; break; } } $selectedCurrency = $selectedCurrency ?? $currencyOptions[0]; @endphp