【发布时间】:2020-05-17 17:15:52
【问题描述】:
我有这两张桌子:
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
订单模型中的关系:
public function products()
{
return $this->belongsToMany('App\Models\Product')->withPivot('quantity')->withTimestamps();
}
我需要这个:
foreach 每个产品,然后将每个产品的价格与order_product(quantity)?? 中的第三个表相乘
我的闭嘴:
foreach ($order->products as $product) {
$total_price = $product->pivot->quantity * $product->price;
}
我需要在此之后将总价格与枢轴(数量)相乘?
【问题讨论】:
-
这能回答你的问题吗? How to count the total price of order?