Recording last login information is useful and you can easily save and update the last login time and IP address of the client.
You can achieve this in several ways but I am gonna show you very simple and effective technique, just add the below-shown method to the login Controller – App\Http\Controllers\Auth\LoginController.php
1 2 3 4 5 6 |
function authenticated(Request $request, $user) { $user->last_login = Carbon::now(); $user->last_login_ip = $request->getClientIp(); $user->save(); } |
If you see you can find the authenticated()
method inside the \Illuminate\Foundation\Auth\AuthenticatesUsers.php
trait file and this method will be called after each successful login. So we are overriding this method in our login controller to update the last login time and IP of the client.
I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.
I am Arjun from Hyderabad (India). I have been working as a software engineer from the last 7+ years, and it is my passion to learn new things and implement them as a practice. Aside from work, I like gardening and spending time with pets.
It work! Fast and easy. Thank you very much!