I am making an accounting system in Laravel in which I have products, and clients. I want to set separate price of each product for each client i.e without setting percentage for each discount. For this I have made a separate table for prices.
My table schema is
Products(id,name,category,stock)
Clients(id,name,email,city)
Prices(product_id,price_id,price(String))
But I am unable to set Laravel relationship . I am making a prices function in product table as
public function prices()
{
return $this->belongsToMany('Client','prices','product_id','client_id');
}
and in client table as
public function prices()
{
return $this->belongsToMany('Product','prices','client_id','product_id');
}
but I am unable to use $product->prices to get prices etc. How can I use this kind of relationship in Laravel ?