Although there's many ways to do this in Laravel, the simplest way is with a piece of web middleware. When an authenticated user visits a route in our application, we want to store the timestamp in the database for use later on.
We also want to make sure this field is "fillable", so add last_active_at to the protected $fillable array on your User model. As well as being able to update last_active_at using User::update(), we want to cast it to a Carbon\Carbon instance when using it so that we can make use of time comparison methods.
If you want to track your users activity across all routes, it should be registered under the web array in App\Http\Kernel: If you only want to track the latest activity for particular routes, you can register the middleware as part of your route registration: