getting data from many-to-many relationship laravel
<p>I have this relationship:</p>

<p>Product:</p>

<pre><code>public function cities()
{
   return $this-&gt;belongsToMany('App\Cities', 'product_price_in_city', 'products_id', 'city_id')-&gt;withPivot('product_price_city');
}
</code></pre>

<p>Cities:</p>

<pre><code>public function products()
{
   return $this-&gt;belongsToMany('App\Product', 'product_price_in_city', 'city_id', 'products_id')-&gt;withPivot('product_price_city');
}
</code></pre>

<p>Now if I need to get a price for a particular product in that city, how can I do that in Product or Cities Model?</p>

<p>Something like this:</p>

<p>I did this in Product model.
I know this is wrong, but how should I do something like this?</p>

<pre><code>public function getProductRateForCity($city_id)
{
    return $this-&gt;cities()-&gt;where('city_id', $city_id)-&gt;where('product_id', $this-&gt;id);
}
</code></pre>