title: Laravel observer for pivot table
body: <p>I've got a observer that has a update method:</p>
  
  <p><strong>ObserverServiceProvider.php</strong></p>
  
  <pre><code>public function boot()
  {
      Relation::observe(RelationObserver::class);
  }
  </code></pre>
  
  <p><strong>RelationObserver.php</strong></p>
  
  <pre><code>public function updated(Relation $relation)
  {
      $this-&gt;cache-&gt;tags(Relation::class)-&gt;flush();
  }
  </code></pre>
  
  <p>So when I update a relation in my controller:</p>
  
  <pre><code>public function update(Request $request, Relation $relation)
  {
       $relation-&gt;update($request-&gt;all()));
       return back();
  }
  </code></pre>
  
  <p>Everything is working as expected. But now I've got a pivot table. A <strong>relation</strong> <code>belongsToMany</code> products. </p>
  
  <p>So now my controller method looks like this:</p>
  
  <pre><code>public function update(Request $request, Relation $relation)
  {
      if(empty($request-&gt;products)) {
          $relation-&gt;products()-&gt;detach();
      } else {
          $relation-&gt;products()-&gt;sync(collect($request-&gt;products)-&gt;pluck('id'));
      }
  
      $relation-&gt;update($request-&gt;all());
  
      return back();
  }
  </code></pre>
  
  <p>The problem is that the observer is not triggered anymore if I <strong>only</strong> add or remove products. </p>
  
  <p>How can I trigger the observer when the <code>pivot table</code> updates aswel?</p>
  
  <p>Thanks</p>