Last Login event registration
Today I worked on my application to record last login date and time for the users. After reading this documentation this is how I implemented in my project.
protected $listen = [
'Illuminate\Auth\Events\Login' => [
'App\Listeners\LogLastLogin',
],
];
Then ran the artisan command
php artisan event:generate
This artisan command generate events and listeners.
Then update the handle method under Listeners\LogLastLogin.php
public function handle(Login $event)
{
$event->user->last_login = date('Y-m-d H:i:s');
$event->user->save();
}
Tested and its working fine. Happy days!!!