From 6c6370d352210469ff93502da796877ce0ae4177 Mon Sep 17 00:00:00 2001 From: denisdulici Date: Tue, 23 Jan 2018 17:01:58 +0300 Subject: [PATCH] set last login after login instead of logout --- app/Listeners/Auth/Login.php | 11 ++++++++--- app/Listeners/Auth/Logout.php | 9 --------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/app/Listeners/Auth/Login.php b/app/Listeners/Auth/Login.php index 84ef6d6a9..852989886 100644 --- a/app/Listeners/Auth/Login.php +++ b/app/Listeners/Auth/Login.php @@ -2,7 +2,7 @@ namespace App\Listeners\Auth; -use Auth; +use Date; use Illuminate\Auth\Events\Login as ILogin; class Login @@ -16,9 +16,14 @@ class Login */ public function handle(ILogin $event) { - // Get company - $company = Auth::user()->companies()->first(); + // Set company id + $company = $event->user->companies()->first(); session(['company_id' => $company->id]); + + // Save user login time + $event->user->last_logged_in_at = Date::now(); + + $event->user->save(); } } diff --git a/app/Listeners/Auth/Logout.php b/app/Listeners/Auth/Logout.php index e6674112d..48799f87a 100644 --- a/app/Listeners/Auth/Logout.php +++ b/app/Listeners/Auth/Logout.php @@ -2,7 +2,6 @@ namespace App\Listeners\Auth; -use Jenssegers\Date\Date; use Illuminate\Auth\Events\Logout as ILogout; class Logout @@ -16,14 +15,6 @@ class Logout */ public function handle(ILogout $event) { - if (empty($event->user)) { - return; - } - - $event->user->last_logged_in_at = Date::now(); - - $event->user->save(); - session()->forget('company_id'); } } \ No newline at end of file