laravel - Laravel:如何在 Crinsane 购物车上传递其他参数
问题描述
我必须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
}
]
}
解决方案
@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->选项->购买}}
您应该可以将其设置为要显示的特定行名,并且它应该与表中使用的名称相匹配。
推荐阅读
- image - 是否可以将图像从 Google 地球引擎下载到我的 PC 桌面?
- flutter - 'BuildContext' 不能分配给参数类型'Widget Function(BuildContext, AsyncSnapshot
) 颤振 - sharepoint - Sharepoint 中的版本控制架构
- datetime - 仅显示小时和分钟而不显示日期
- python - 将 .txt 文件转换为 .csv ,其中每一行进入一个新列,每个段落进入一个新行
- php - 处理来自伪装者的 POST 请求
- excel - 在 Do Until 循环内更改变量的问题
- python - 烧瓶:无法将应用程序部署到 Heroku,没有名为“应用程序”的模块
- java - 配置项目 ':path_provider' 时出现问题
- css - 反应引导卡不会并排显示它们