input('locale'); if (! in_array($locale, ['pt_BR', 'en', 'es'], true)) { return back(); } App::setLocale($locale); $request->session()->put('locale', $locale); if ($user = $request->user()) { $user->update(['locale' => $locale]); } // Persist the cookie preference (1 year) used on subsequent visits. $response = back(); $previousPath = (string) parse_url($response->getTargetUrl(), PHP_URL_PATH); // The 3D viewer fetches /city/data via XHR, which can become the // session's "previous URL" and would dump the user on raw JSON. if ($previousPath === '/city/data') { $response = redirect()->route('city.viewer'); } $response->withCookie(cookie('city10-locale', $locale, 60 * 24 * 365, '/', null, false, true)); return $response; } }