Laravel - How count daily accesses in app

752 views Asked by At

I need to show a chart that show the application accesses and I think in create a table to save the user and date that he access.

But for insert in this table I need to know where is laravel did the login authentication. I don't know what is the file and function.

If anyone has a better solution I appreciate that.

Thank you

1

There are 1 answers

0
avirdz On

You can create a global middleware in order to log the accesses. https://laravel.com/docs/5.5/middleware#global-middleware

Then if you don't want to have a lot of logs for the same user, you can use cache with a specific expire time. example: log the user access once every 24hrs.

Another approach is to use the Login events to log user accesses. https://laravel.com/docs/5.2/authentication#events

Illuminate\Auth\Events\Login (this way every logins count as an access)

There is another event added in Laravel version 5.3

Illuminate\Auth\Events\Authenticated (I assume this event is fired every time the user is authenticated)

You can create a Listener to check which of these events is better for your purpose.