Table of contents

laravel logout redirect

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.