2020-10-08 15:38:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2022-11-22 15:15:52 +01:00
|
|
|
use Closure;
|
2020-10-08 15:38:36 +02:00
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class LogUserLastSeen
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
2022-11-22 15:15:52 +01:00
|
|
|
* @param string $guards
|
2020-10-08 15:38:36 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2022-08-02 10:57:16 +02:00
|
|
|
public function handle($request, Closure $next, ...$guards)
|
2020-10-08 15:38:36 +02:00
|
|
|
{
|
2022-03-19 00:14:20 +01:00
|
|
|
$guards = empty($guards) ? [null] : $guards;
|
2020-10-08 15:38:36 +02:00
|
|
|
|
2022-03-19 00:14:20 +01:00
|
|
|
foreach ($guards as $guard) {
|
2022-03-24 14:58:30 +01:00
|
|
|
// We do not track activity of:
|
|
|
|
// - Guest
|
|
|
|
// - User authenticated against a bearer token
|
|
|
|
// - User authenticated via a reverse-proxy
|
2022-11-22 15:15:52 +01:00
|
|
|
if (Auth::guard($guard)->check() && ! $request->bearerToken() && config('auth.defaults.guard') !== 'reverse-proxy-guard') {
|
2022-03-19 00:14:20 +01:00
|
|
|
Auth::guard($guard)->user()->last_seen_at = Carbon::now()->format('Y-m-d H:i:s');
|
|
|
|
Auth::guard($guard)->user()->save();
|
|
|
|
break;
|
|
|
|
}
|
2020-10-08 15:38:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $next($request);
|
|
|
|
}
|
|
|
|
}
|