Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am using Laravel 5.4 and trying to implement authentication system. I used php artisan command make:auth to setup it. I edited the views according to my layout. Now, when I am trying to logout it throwing me this error

NotFoundHttpException in RouteCollection.php line 161:

could any one help me how to logout?

like image 200
Y.EzzEldin Avatar asked Apr 24 '17 10:04

Y.EzzEldin


People also ask

How do I logout of all devices in laravel?

This method requires the user to provide their current password, which your application should accept through an input form: use Illuminate\Support\Facades\Auth; Auth::logoutOtherDevices(request('password')); When the logoutOtherDevices method is invoked, the user's other sessions will be invalidated entirely, meaning ...


1 Answers

In your web.php (routes):

add:

Route::get('logout', '\App\Http\Controllers\Auth\LoginController@logout'); 

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

like image 55
Tauras Avatar answered Oct 16 '22 01:10

Tauras