title: Using Model Events Listener in Laravel 5
body: <p>I would like to make sure that I correctly used model events listeners in Laravel 5 and I didn't messed up nothing (listener vs handler?). My solution works fine, but I wonder if I developed according to concept and convention of Laravel 5.</p>
  
  <p><strong>Goal:</strong>
  Always set $issue->status_id on some value when model is saving.</p>
  
  <p>In app\Providers\EventServiceProvider.php</p>
  
  <pre><code>&lt;?php namespace App\Providers;
  
  ...
  
  class EventServiceProvider extends ServiceProvider {
  
      ...
  
      public function boot(DispatcherContract $events)
      {
          parent::boot($events);
  
          Issue::saving('App\Handlers\Events\SetIssueStatus');
      }
  
  }
  </code></pre>
  
  <p>In app\Handlers\Events\SetIssueStatus.php</p>
  
  <pre><code>&lt;?php namespace App\Handlers\Events;
  
  ...
  
  class SetIssueStatus {
  
      ...
  
      public function handle(Issue $issue)
      {
          if (something)
          {   
              $issueStatus = IssueStatus::where(somethingElse)-&gt;firstOrFail();
          }
          else 
          {
              $issueStatus = IssueStatus::where(somethingAnother)-&gt;firstOrFail();
          }
  
          // issue_status() is One-to-One relations with IssueType (belongsTo)
          $issue-&gt;issue_status()-&gt;associate($issueStatus);
      }
  
  }
  </code></pre>
  
  <p>Thank you for your time.</p>