I have this two tables:
Orders:
id - status -user_id - address_id
1 await 1 1
products:
id - name - price - quantity
1 test1 100$ 5
2 test2 50$ 5
order_product:
order_id - product_id - quantity
1 1 2
1 2 2
Relation in Order Model:
public function products()
{
return $this->belongsToMany('App\Models\Product')->withPivot('quantity')->withTimestamps();
}
I need this:
foreach each product then MULTIPLY the price of each product with the third table in order_product(quantity)
??
My Shut:
foreach ($order->products as $product) {
$total_price = $product->pivot->quantity * $product->price;
}
I need after this to sum the total price after MULTIPLY with pivot(quantity) ?