Skip to content

Commit

Permalink
set last login after login instead of logout
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Jan 23, 2018
1 parent 153f745 commit 6c6370d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
11 changes: 8 additions & 3 deletions app/Listeners/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Listeners\Auth;

use Auth;
use Date;
use Illuminate\Auth\Events\Login as ILogin;

class Login
Expand All @@ -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();
}
}
9 changes: 0 additions & 9 deletions app/Listeners/Auth/Logout.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace App\Listeners\Auth;

use Jenssegers\Date\Date;
use Illuminate\Auth\Events\Logout as ILogout;

class Logout
Expand All @@ -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');
}
}

0 comments on commit 6c6370d

Please sign in to comment.