Laravel - log out of a specific user

I know how to log in, but how do I log out of the specified user from the application? It seems that this is not enough.

+8
authentication laravel logout
source share
4 answers

This problem occurs when you are an administrator and want to block some users. Then, when you block a user, you want to log out personally. For laravel 5.2 (maby for lower versions too) you can create an average program:

Multimedia creation

namespace App\Http\Middleware; use Closure; use Illuminate\Support\Facades\Auth; class BockedUser { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @param string|null $guard * @return mixed */ public function handle($request, Closure $next, $guard = null) { $user = Auth::user(); if ($user and $user->is_bocked) { Auth::logout(); return redirect('/login'); } return $next($request); } } 

And in app / Http / Kernel.php under $ middlewareGroups> 'web' add \ App \ Http \ Middleware \ BockedUser :: class. I believe that all your routes are in Route::group(['middleware' => 'web'], function () { .. all your routes ..}

+2
source share

You can do this to log off offline in laravel 4.2 and you use multi auth

 /* for normal user logout */ Auth::user()->logout(); /* for admin user logout */ Auth::admin()->logout(); /* for manager user logout */ Auth::manager()->logout(); 

since you made auth user

0
source share

You can log out when it gets access to any authenticated function, such as editing a profile, editing a message, creating a message, etc. For example:

  public function edit() { if (!\Auth::user()->active) { \Auth::logout(); return redirect('/'); } // code here } 
0
source share

You can make a logout route using the GET method. Thus, you can easily log out of a specific user with a link (the link that you specified on your route). By default, Laravel uses POST to prevent other users. You can also add middleware to this route so that other users cannot do this. I hope this help.

0
source share

All Articles