DEV Community

Cover image for Laravel 8 Logout Redirect Implementation
Code And Deploy
Code And Deploy

Posted on

Laravel 8 Logout Redirect Implementation

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/laravel-8-logout-redirect-implementation

Do you want a sample code on how to add Laravel 8 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 in 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');
    }
}
Enter fullscreen mode Exit fullscreen mode

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/laravel-8-logout-redirect-implementation if you want to download this code.

Happy coding :)

Top comments (0)