DEV Community

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

Posted on

2 1

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 :)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay