close

How to logout and redirect to login page using Laravel 5.4?

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error How to logout and redirect to login page using Laravel 5.4? in php. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How to logout and redirect to login page using Laravel 5.4 Error Occurs?

Today I get the following error How to logout and redirect to login page using Laravel 5.4? in php.

How To Solve logout and redirect to login page using Laravel 5.4 Error ?

  1. How To Solve logout and redirect to login page using Laravel 5.4 Error ?

    To Solve logout and redirect to login page using Laravel 5.4 Error You can use the following in your controller:
    return redirect('login')->with(Auth::logout());

  2. How to logout and redirect to login page using Laravel 5.4?

    To Solve logout and redirect to login page using Laravel 5.4 Error You can use the following in your controller:
    return redirect('login')->with(Auth::logout());

Solution 1

In your web.php (routes):

add:

Route::get('logout', '\App\Http\Controllers\Auth\[email protected]');

In your LoginController.php

add:

public function logout(Request $request) {
  Auth::logout();
  return redirect('/login');
}

Also, in the top of LoginController.php, after namespace

add:

use Auth;

Now, you are able to logout using yourdomain.com/logout URL or if you have created logout button, add href to /logout

Solution 2

You can use the following in your controller:

return redirect('login')->with(Auth::logout());

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read

Leave a Comment