title: Laravel Eloquent get model by scope on associated model
body: <p>I have an Eloquent model <code>Foo</code> which has a field <code>bar_id</code>. I define the relationship between them in the <code>Foo</code> model:</p>
  
  <pre><code>public function Bar()
  {
      $this-&gt;belongsTo('App\Bar');
  }
  </code></pre>
  
  <p>The <code>Bar</code> model has a <code>baz_id</code>, and a scope to get all <code>Bar</code>s which have a particular <code>baz_id</code>. This is the scope in my <code>Bar</code> model:</p>
  
  <pre><code>public function scopeFromBaz($query, $bazId)
  {
      return $query-&gt;where('baz_id', $bazId)
  }
  </code></pre>
  
  <p>I now want to make a call of all <code>Foo</code>s where their associated <code>Bar</code> has a <code>baz_id</code> of <code>1</code>. How do I do this? I've tried:</p>
  
  <pre><code>Foo::where('bar', function($query) {
      $query-&gt;fromBaz(1);
  });
  </code></pre>
  
  <p>But that produces the error </p>
  
  <blockquote>
    <p>Call to undefined method Illuminate\Database\Query\Builder::fromBaz()</p>
  </blockquote>