Table of contents
Do you want a sample code on how to add Laravel 8, 9 logout redirect? In this post, I will give you an example and implementation of how to do it. After we log out our user we need to redirect it to a specific route so this is an important task if you're handling this.
Â
To shorten this post please follow our previous post about Laravel logout.
Â
In our Logout Controller, we will add our Laravel logout redirect so that the authenticated user will be redirected to the specific route.
Â
Here is the code sample below.
Â
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Session;
class LogoutController extends Controller
{
/**
* Log out account user.
*
* @return \Illuminate\Routing\Redirector
*/
public function perform()
{
Session::flush();
Auth::logout();
return redirect('your_route');
}
}
Â
I hope this is helpful to you. Thank you for visiting our blog.
Read next