需要一些帮助,以将两个foreach循环的总数相加,第一个foreach将项目加载到购物篮中,接下来将项目与产品进行匹配,我需要获取购物篮中所有项目的总数,包括数量< / p>
我尝试使用£{{$product->price * $basket->qty}}
,但它只返回购物篮中最后一个项目的总计
这是foreach代码:
@foreach(Products::where("id", "=", $basket->product_id)->get() as $product)
<div class="row cart_items_row">
<div class="col">
<div class="cart_item d-flex flex-lg-row flex-column align-items-lg-center align-items-start justify-content-start">
<div class="cart_item_product d-flex flex-row align-items-center justify-content-start">
<div class="cart_item_image">
<div><img src="https://www.cncspace.co.uk/assets/images/{{$product->cover_photo}}.png" alt=""></div>
</div>
<div class="cart_item_name_container">
<div class="cart_item_name"><a href="#">{{$product->name}}</a></div>
<div class="cart_item_edit"><a href="#">Edit Product</a></div>
</div>
</div>
<div class="cart_item_price">£{{$product->price}}</div>
<div class="cart_item_price">{{$basket->colour}}</div>
<div class="cart_item_price">{{$basket->qty}}</div>
<div class="cart_item_price">£{{$product->price * $basket->qty}}</div>
</div>
</div>
</div>
@endforeach
@endforeach
我试图求出所有产品的总和,乘以数量,然后相加,但是它只显示出最后结果,有什么想法吗?
答案 0 :(得分:0)
我看不到第二条@foreach语句正在查看您的代码