Quick tip of the day. Default Laravel Auth comes with User table and model, but without logging capability, so we need to build it ourselves. Fortunately, it’s very easy, I will show you one .

Let’s say that we want to save user’s last time and IP in the same table.
So we start with database migration:

Then we fill it with these fields:

Next, we need to add these fields as fillables in app/User.php model:

Finally, how do we fill them in? You need to know that there is authenticated() method in the AuthenticatesUsers trait. It’s called every time someone logs in.

In trait this method is empty. So we have freedom to override it in LoginController and add whatever we need.


And, that’s it! Here’s what we have in users table after log in:

laravel last login ip address

Source link
thanks you RSS link
( https://laraveldaily.com/save-users-last-login-time-ip-address/)


Please enter your comment!
Please enter your name here