4 years ago

login event handling in laravel 5

Posted 4 years ago by erikbelusic

i am trying to hook to the login even in my L5 app to set last login time and IP address. i can make it work with the following:

Event::listen('auth.login', function($event)
    Auth::user()->last_login = new DateTime;
    Auth::user()->last_login_ip = Request::getClientIp();

however, i am wondering what the best way to do this in L5 is with the event handler object. i tried creating an event handler and adding auth.login as an array key in the events service provider, however that didnt work. im not sure if that is possible or not with the auth.login event. if it isnt, where is the most appropriate place to put the above code. for testing, i put it in my routes.php file, but i know that isnt where it should be.

Please sign in or create an account to participate in this conversation.