Laravel force logout user


Laravel force logout user

Add force_logout column in users table.

Create ForceLogout Middleware in app/Http/Middleware/ForceLogout.php


namespace App\Http\Middleware;

use Auth;
use Closure;

class ForceLogout
    public function handle($request, Closure $next)
        $user = Auth::user();

        if (isset($user->force_logout) && $user->force_logout == true) {

            $user->force_logout = false;

            // Log out here

            return redirect()->route('login');

        return $next($request);

Open up the app/Http/Kernel.php and add ForceLogout middleware

protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\ForceLogout::class, // <= add Here

click for more Laravel codes read about laravel middleware