2020-10-08 15:38:36 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
|
|
|
|
use Closure;
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
|
|
|
|
class LogUserLastSeen
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Handle an incoming request.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param \Closure $next
|
2022-03-19 00:14:20 +01:00
|
|
|
* @param string|null $guard
|
2020-10-08 15:38:36 +02:00
|
|
|
* @return mixed
|
|
|
|
*/
|
2022-03-19 00:14:20 +01:00
|
|
|
public function handle($request, Closure $next, ...$quards)
|
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) {
|
|
|
|
// Activity coming from a client authenticated with a personal access token is not logged
|
|
|
|
if( Auth::guard($guard)->check() && !$request->bearerToken()) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|