Support the ongoing development of Laravel.io →
Authentication
Last updated 2 years ago.
0

Auth::logout() removes user's data from current session, it does nothing to other sessions.

So you either need to somehow destroy other user's session, and I'm not sure there's a standard way to do.

Or, alternatively, mark that user for logout (in, say, an additional field in users table), and check that mark in app/Http/Middleware/Authenticate middleware:

	public function handle($request, Closure $next)
	{
		if ( ( $user = $this->auth->getUser() ) && $user->forceLogout) {
			$user->forceLogout = false;
			$user->save();
			$this->auth->logout();
		}
		if ($this->auth->guest())
		{
			if ($request->ajax())
			{
				return response('Unauthorized.', 401);
			}
			else
			{
				return redirect()->guest('auth/login');
			}
		}

		return $next($request);
	}
0

Sign in to participate in this thread!

Eventy

Your banner here too?

kdoichinov kdoichinov Joined 20 Oct 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.