I am new in laravel(using version 8) and working on "Logout section" but unable to logout,still getting email in session (after logout),How can i logout ? Here is my view file
<a href="{{ route('logout') }}">
<i ></i>
Logout
</a>
Here is my Routes(web.php)
Route::get('logout', [AdminController::class, 'logout'])->name('logout');
Here is my controller code,How can i logout ? Thank you in advance.
function logout()
{
Auth()->logout();
return redirect('/')->with('logout_message', 'You have been logged out');;
}
CodePudding user response:
You should not only logout, but also invalidate the session.
Try something like this:
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
/**
* Log the user out of the application.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function logout(Request $request)
{
Auth::logout();
$request->session()->invalidate();
$request->session()->regenerateToken();
return redirect('/');
}
See docs: https://laravel.com/docs/9.x/authentication#logging-out