I know how to log in a user, but how do I log out a specified user from the application? There doesn't seem to be enough coverage on this.
To manually log users out of your application, you may use the logout method provided by the Auth facade.
Where is logout function Laravel? Step 1: Create a route. Navigate routes/web. php then put the following code below: Route::group(['middleware' => ['auth']], function() { /** * Logout Route */ Route::get('/logout', 'LogoutController@perform')->name('logout.
As you can see I added Auth::logoutOtherDevices() with the parameter of password. So that we can enable to log out of the other active devices.
Guards define how users are authenticated for each request. For example, Laravel ships with a session guard which maintains state using session storage and cookies. Providers define how users are retrieved from your persistent storage.
This problem occures when you are admin and want to block some user. Then when you block user you want to logout him imidietly. For laravel 5.2 (maby for lower versions too) you can create middelware:
Create middelware
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 in section $middlewareGroups > 'web' add \App\Http\Middleware\BockedUser::class. I assmue that all your routes are in Route::group(['middleware' => 'web'], function () { .. all your routes ..}
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