protected function loadLocales() { //Set the default locale as the first one. $locales = Translation::groupBy('locale')->lists('locale'); if ($locales instanceof Collection) { $locales = $locales->all(); } $langs = Language::lists('code'); if ($langs instanceof Collection) { $langs = $langs->all(); } $locales = array_merge($locales, $langs); sort($locales); $locales = array_merge([config('app.locale')], $locales); return array_unique($locales); }
public function languageAndCurrencyByCountry($id) { $country = Country::find($id); if ($country) { $code = $country->code; $languages = PunicTerritory::getLanguages($code, 'of', true); $languages = array_map(function ($value) { return str_replace('_', '-', $value); }, $languages); $allLanguages = Language::lists('code')->toArray(); $languages = array_intersect(array_merge((array) $languages, ['en']), $allLanguages); $language = head($languages); $allCurrencies = Currency::lists('code')->toArray(); $currencies = PunicCurrency::getCurrencyForTerritory($code); $currencies = array_intersect(array_merge((array) $currencies, ['GBP']), $allCurrencies); $currency = head($currencies); $language = Language::whereCode($language)->first(); $currency = Currency::whereCode($currency)->first(); return ['language_id' => $language->id, 'currency_id' => $currency->id]; } else { return response('error', 404); } }