I have this relationship:
Product:
public function cities()
{
return $this->belongsToMany('App\Cities', 'product_price_in_city', 'products_id', 'city_id')->withPivot('product_price_city');
}
Cities:
public function products()
{
return $this->belongsToMany('App\Product', 'product_price_in_city', 'city_id', 'products_id')->withPivot('product_price_city');
}
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?
Something like this:
I did this in Product model. I know this is wrong, but how should I do something like this?
public function getProductRateForCity($city_id)
{
return $this->cities()->where('city_id', $city_id)->where('product_id', $this->id);
}
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1lJAGwI
via IFTTT
Aucun commentaire:
Enregistrer un commentaire