Skip to content

Instantly share code, notes, and snippets.

@georgewritescode
Created January 27, 2018 02:41
Show Gist options
  • Save georgewritescode/b0c56d52174d99345ab331b9c90a2e7a to your computer and use it in GitHub Desktop.
Save georgewritescode/b0c56d52174d99345ab331b9c90a2e7a to your computer and use it in GitHub Desktop.
redis lastseen
<?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);
}
}
@nathanheffley
Copy link

Instead of !Auth::check why don't you use Auth::guest instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment