Reputation: 404
I'm using laravel 5.2 framework and I have created auth with the php artisan make:auth
command. I have this in my AuthController:
protected $redirectTo = '/';
protected $redirectPath = '/students';
protected $loginPath = '/auth/login';
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
And these in my routes.php file:
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('/home', 'HomeController@index');
Route::get('/', 'HomeController@index');
Route::get('/students/', 'StudentsController@showStudents');
// Authentication routes...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// Registration routes...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
});
While logging in/registering everything works perfect but when i press the logout button nothing changes and I'm still logged in. What I want is to redirect to the auth/login view after clicking that Logout button. Please help.
Upvotes: 1
Views: 1961
Reputation: 6539
The problems come AuthController middleware since the default router name is " logout
" and if you have change the name middleware will not recognized your router name.
You just need to keep the default name router OR fix your construct middleware.
Route::get('logout', [ 'uses' => 'Auth\AuthController@getLogout', 'as' => 'logout' ]);
In Authcontroller
,
public function __construct(){
$this->middleware('guest', [ 'except' => 'logout' ]); // Default router name is "logout"
}
Hope it will help you :-)
Upvotes: 1
Reputation: 161
Add this to AuthController.php
public function getLogout(){
return redirect('Auth/login');
}
Upvotes: 0