getLocale(); $returnTo = $this->returnTo($request); Auth::guard('web')->logout(); $request->session()->invalidate(); $request->session()->regenerateToken(); // The login page stays in the language the user had chosen. $request->session()->put(SetLocale::SESSION_KEY, $locale); // "Change user" on a machine console: the next user signs in back to the console. if ($returnTo !== null) { $request->session()->put('url.intended', $returnTo); } return redirect()->route('login')->with('status', __('auth.logged_out')); } /** * A page of this application to return to after the next login, never * another site. */ private function returnTo(Request $request): ?string { $returnTo = (string) $request->input('return_to', ''); $base = rtrim(url('/'), '/').'/'; return $returnTo !== '' && Str::startsWith($returnTo, $base) && ! Str::contains($returnTo, ['\\', '@']) ? $returnTo : null; } }