title: Laravel 5.2 Login Event Handling
body: <p>In the database I have a table users with column last_login_at. Everytime when some user logs in - I want to uptade <em>last_login_at</em>. </p>
  
  <p>So, I created app/Listeners/<strong>UpdateLastLoginOnLogin.php</strong>:</p>
  
  <pre><code>namespace App\Listeners;
  
  use Carbon\Carbon;
  
  class UpdateLastLoginOnLogin
  {
      public function handle($user, $remember)
      {
          $user-&gt;last_login_at = Carbon::now();
  
          $user-&gt;save();
      }
  }
  </code></pre>
  
  <p>In app/Providers/EventServiceProvider:</p>
  
  <pre><code>    protected $listen = [
          'auth.login' =&gt; [
              'App\Listeners\UpdateLastLoginOnLogin',
          ],
      ];
  </code></pre>
  
  <p>BUT this doesn't work, event is not handled. The same problem has already been mentioned here: <a href="https://stackoverflow.com/questions/34974192/eventserviceprovider-mapping-for-laravel-5-2-login">EventServiceProvider mapping for Laravel 5.2 login</a> but without solution. I have tried to do like this:</p>
  
  <p>...</p>
  
  <pre><code>use Illuminate\Auth\Events\Login;
  
  class UpdateLastLoginOnLogin
  {
      public function handle(Login $event)
      {
          $event-&gt;user-&gt;last_login_at = Carbon::now();
          $event-&gt;user-&gt;save();
      }
  }
  </code></pre>
  
  <p>and:</p>
  
  <pre><code>protected $listen = [
      'Illuminate\Auth\Events\Login' =&gt; [
          'App\Listeners\UpdateLastLoginOnLogin',
      ],
  ];
  </code></pre>
  
  <p>But it doesn't work.</p>
  
  <p>Also, I checked this: <a href="https://laracasts.com/discuss/channels/general-discussion/login-event-handling-in-laravel-5" rel="nofollow noreferrer">https://laracasts.com/discuss/channels/general-discussion/login-event-handling-in-laravel-5</a> but <strong>php artiasn clear-compiled</strong> didn't solve the problem.</p>
  
  <p><strong>EDIT:</strong> FOR OTHER DETAILS, HERE'S A LINK TO THE PROJECT which is actually exactly the same (it is done in the same way): <a href="https://github.com/tutsplus/build-a-cms-with-laravel" rel="nofollow noreferrer">https://github.com/tutsplus/build-a-cms-with-laravel</a></p>