cookie('locale', config('app.locale')); } return $response; } public function detect(Request $request) { $locale = $request->input('lang') ?: ($request->cookie('locale') ?: $request->getPreferredLanguage()); // If current locale is an alias of other locale if (($info = array_get(config('locales'), $locale)) && ($alias = array_get($info, 'alias'))) { $locale = $alias; } app()->setLocale($locale); AfterSessionBooted::$jobs[] = function () { session(['locale' => config('app.locale')]); }; } }