F
F
freeeeez2018-06-28 16:28:59
Laravel
freeeeez, 2018-06-28 16:28:59

How to update user visit time in Laravel?

In the users database, there is a line lasttime, where the date of the last visit is stored in the TIMESTAMP format. How to update it on any page load, so as not to write an update function in each controller? Now I expose it only when logging in in the form, but how can I make it so that after logging in, when loading any page, it is updated?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
Vasyl Fomin, 2018-06-28
@freeeeez

1. Make a middleware for all routes available to the user ( implementation example ).
2. Middlewar will update the array of active users, we write the array itself, for example, to the server cache.
3. Check this array, for example, through cron every minute. If the user id is in the array, we update the entry in the database in the user table.
The best option for not heavily loaded sites. The main thing is that it does not depend on user requests, but the minimum accuracy depends, for example, on the cron settings.

C
Camaro67, 2018-06-28
@Camaro67

Middleware

K
Konstantin B., 2018-06-28
@Kostik_1993

Middleware
But in general this is the bottom. For this, it’s better to connect a radish and write the time into it, otherwise, with an already small load, judging by the questions you ask, your server will wave to you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question