Skip to content

Commit

Permalink
Merge pull request #57 from robinklaassen/feature/last-login
Browse files Browse the repository at this point in the history
fix: last login date
  • Loading branch information
robinklaassen committed Oct 20, 2019
2 parents d6debb6 + d066328 commit 701350f
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 38 deletions.
Empty file removed app/Handlers/Commands/.gitkeep
Empty file.
Empty file removed app/Handlers/Events/.gitkeep
Empty file.
32 changes: 0 additions & 32 deletions app/Handlers/Events/AuthLoginEventHandler.php

This file was deleted.

21 changes: 21 additions & 0 deletions app/Listeners/SetLastLoginDate.php
@@ -0,0 +1,21 @@
<?php

namespace App\Listeners;

use Illuminate\Auth\Events\Login as LoginEvent;

class SetLastLoginDate
{
/**
* Handle the event, sets the user's last_login to current dateTime
*
* @param object $event
* @return void
*/
public function handle(LoginEvent $event)
{
$user = $event->user;
$user->last_login = new \DateTime;
$user->save();
}
}
16 changes: 10 additions & 6 deletions app/Providers/EventServiceProvider.php
@@ -1,19 +1,24 @@
<?php namespace App\Providers;
<?php

namespace App\Providers;

use App\Listeners\SetLastLoginDate;
use Illuminate\Auth\Events\Login;
use Illuminate\Contracts\Events\Dispatcher as DispatcherContract;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider {
class EventServiceProvider extends ServiceProvider
{

/**
* The event handler mappings for the application.
*
* @var array
*/
protected $listen = [
'auth.login' => [
'App\Handlers\Events\AuthLoginEventHandler',
],
Login::class => [
SetLastLoginDate::class,
]
];

/**
Expand All @@ -28,5 +33,4 @@ public function boot()

//
}

}

0 comments on commit 701350f

Please sign in to comment.