Laravel force logout user
Add force_logout column in users table.
Create ForceLogout Middleware in app/Http/Middleware/ForceLogout.php
<?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;
$user->save();
// Log out here
Auth::logout();
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
]
];
</body>
click for more Laravel codes read about laravel middleware