Laravel - retrieving a model through another model's builder
<p>I have the following code:</p>

<pre><code>$stores = $this-&gt;user-&gt;markets()-&gt;stores();
</code></pre>

<p>Which gives the error: </p>

<pre><code>Call to undefined method Illuminate\Database\Query\Builder::stores()
</code></pre>

<p>I've read about using <code>with()</code>:</p>

<pre><code>$stores = $this-&gt;user-&gt;markets()-&gt;with('stores');
</code></pre>

<p>This works, but it is retrieving <code>markets</code> with <code>stores</code> in each market. How do I get a builder object of <code>stores</code> that belong to the user's <code>markets</code>?</p>

<p>User model:</p>

<pre><code>class User extends Eloquent {
    public function markets()
    {
        return $this-&gt;belongsToMany('Market');
    }
}
</code></pre>

<p>Market model:</p>

<pre><code>class Market extends Eloquent {
    public function stores()
    {
        return $this-&gt;belongsToMany('Store');
    }
}
</code></pre>