Laravel 5 - How to logout a user from all of his devices using Redis
<p>I'm building a laravel application where A user logged in other device and While logged out I want to force him to logged out from other device also. How do I implement in laravel. </p>

<p>Personally I have used Redis Server. While running the program I have run <code>redis-server.exe</code> also.And I'm in Windows. 
I have changed the .env file also with <code>CACHE_DRIVER=redis SESSION_DRIVER=redis</code> 
Besides Redis already installed with laravel I have also installed <code>"predis/predis": "~1.0"</code></p>

<p>And Here is my Controller where I have written the login for forcing the user from logged out from other device.</p>

<p>In Signin controller when I dd() the <code>$redis</code> I see the session created for that user but when I logged in and when going to logout I dd() the <code>$userSessions</code> But see empty so it means nothing stored in sessions table to compare. </p>

<p>If anyone find any solution please help me to find it out. Thanks In Advance.</p>

<p>Controller:</p>

<pre><code>  public function postSignIn(Request $request)
  {       

   if (Auth::attempt(['email' =&gt; $request['email'], 'password' =&gt;$request['password'] ]) ) {  
      $redis = \Redis::connection();   
      $userId = Auth::user()-&gt;id;
      $redis-&gt;sadd('users:sessions:' . $userId,Session::getId());      
      return redirect()-&gt;route('main');
    }
    return redirect()-&gt;back();
}



public function getLogout()
{
    $redis = Redis::connection();
    $userId =Auth::user()-&gt;id;
    $userSessions = $redis-&gt;smembers('user:sessions:' . $userId);
    $redis-&gt;sadd('users:sessions:'.$userId,Session::getId());
    $currentSession = Session::getId();
    foreach ($userSessions as $sessionId) {
      if ($currentSession == $sessionId) {
        continue; 
      }
      $redis-&gt;srem('user:sessions:' . $userId, $sessionId);
      $redis-&gt;del('laravel:' . $sessionId);
      \Session::setId( $sessionId ); 
        \Session::clear();
    }
    Auth::logout();
    return redirect()-&gt;route('main');
}
</code></pre>