title: Laravel Eloquent Events - implement to save model if Updated
body: <p>I have such code in the controller:</p>
  
  <pre><code>for($i=0; $i&lt;$number_of_tourists; $i++) {
  
  $tourist = Tourist::updateOrCreate(['doc_number' =&gt; $request['doc_number'][$i]],
  $tourist_to_update);
  
  }
  </code></pre>
  
  <p>so, the updateOrCreate method can 1) Update record, 2) Create a new one 3) Leave record untouched if $tourist_to_update equals to what's already in the DB.</p>
  
  <p><strong>I want to save $tourist_to_update into $array[] only when a record in 'tourist" table is being updated</strong> (not when a new record created or nothing changes).</p>
  
  <p>As I know, there are Eloquent events <a href="https://laravel.com/docs/5.4/eloquent#events" rel="nofollow noreferrer">https://laravel.com/docs/5.4/eloquent#events</a>  which have <em>updating</em> and <em>updated</em> events, which seem to match my needs.</p>
  
  <p>The problem is I watched&amp;read several tutorials and still don't understand how to use them.</p>
  
  <p>I know how-to-register a Eloquent event  in Tourist model:</p>
  
  <pre><code>protected static function boot()
  {
      parent::boot();
  
      static::updating(function ($model) {
  
      });
  }
  </code></pre>
  
  <p>Could anyone explain how can I achive my goal with Eloquent events?</p>
  
  <p>Thank you in advance.</p>