我必须将purchase_prices
表中的product
字段粘贴到crinsane购物车上,以便我可以从每笔交易中看到profit
并将其保存到数据库中。>
这是我在 CartController
上的代码$product = Product::find($id);
Cart::add([
'id' => $product->id,
'name' => $product->name,
'qty' => 1,
'price' => $product->sell_price,
'options' => ['purchase' => $product->purchase_price]
]);
return back();
但购买的商品未存储
Collection {#257 ▼
#items: array:1 [▼
"370d08585360f5c568b18d1f2e4ca1df" => CartItem {#258 ▼
+rowId: "370d08585360f5c568b18d1f2e4ca1df"
+id: 2
+qty: 1
+name: "Beras B"
+price: 12000.0
+weight: 1.0
+options: CartItemOptions {#259 ▼
#items: []
}
-associatedModel: null
-taxRate: 0
-discountRate: 0
}
]
}
答案 0 :(得分:0)
@foreach ($cartItems as $cartItem)
<?php $no++ ?>
<tr>
<td>{{$no}}</td>
<td>{{$cartItem->name}}</td>
<td>{{$cartItem->qty}}</td>
<td>{{$cartItem->price}}</td>
<td>{{$cartItem->options->purchase}}</td>
<td></td>
<td>
<a href="" class="btn btn-success btn-sm">Update</a>
<a href="" class="btn btn-danger btn-sm">Delete</a>
</td>
</tr>
@endforeach
我看到您在编写时试图从表中检索多行
{{$$ cartItem-> options-> purchase}}
您应该将其更改为要显示的特定行名称,并且该名称应与表中使用的名称匹配。