title: Querying a related model within a Laravel query scope
body: <p>I have a query scope method that filters results on a Foo model by the author of the model. The complication is that the author is not directly related. </p>
  
  <p>Foo belongs to Bar and Bar belongs to User. If Foo belonged to User, I could just do this:</p>
  
  
  
  <pre class="lang-php prettyprint-override"><code>public function scopeAuthorOnly($query, User $user)
  {
      return $query-&gt;whereuser_id($user-&gt;id);
  }
  </code></pre>
  
  <p>This obviously won't work as the Foo model has no user_id column and instead has a bar_id column. However I'm not sure how I can build the query in a way that would filter the user_id.</p>
  
  <p>Any pointers?</p>