Created
January 27, 2018 02:41
-
-
Save georgewritescode/b0c56d52174d99345ab331b9c90a2e7a to your computer and use it in GitHub Desktop.
redis lastseen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Redis; | |
class LastSeen | |
{ | |
public function handle($request, Closure $next) | |
{ | |
if (!Auth::check()) { | |
return $next($request); | |
} | |
$redis = Redis::connection(); | |
$key = 'last_seen_' . Auth::id(); | |
$value = (new \DateTime())->format("Y-m-d H:i:s"); | |
$redis->set($key, $value); | |
return $next($request); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Instead of
!Auth::check
why don't you useAuth::guest
instead?