I'm building a very simple app in Laravel 5.2, but when using AuthController
's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check()
and it doesn't change after calling the log out action.
I have this route inside the routes.php file:
Route::get('users/logout', 'Auth\AuthController@getLogout');
and it's outside the
Route::group(['middleware' => ['web']], function ()
statement.
I did also try to add the follow action at the end of the AuthController.php file.
public function getLogout()
{
$this->auth->logout();
Session::flush();
return redirect('/');
}
Do you have any ideas?
EDIT 1
If I clear Google's Chrome cache, it works.
How do I enable authentication in Laravel? You need to Install the laravel/ui Composer bundle and run php artisan ui vue –auth in a new Laravel application. After migrating your database, open http://your-app.test/register or any other URL that's assigned to your application on your browser.
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 ...
I also had similar problem in Laravel 5.2. You should change your route to
Route::get('auth/logout', 'Auth\AuthController@logout');
or in AuthController constructor add
public function __construct()
{
$this->middleware('guest', ['except' => ['logout', 'getLogout']]);
}
That worked for me.
use below code
Auth::logout();
or
auth()->logout();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With