我想收集产品并推送到会话购物车。
$product= Product::find(1);
$product2= Product::find(2);
session(['cart' => collect($product)]);
session(['cart' => session('cart')->push($product2)])
这是我的输出,其中包含一些虚拟数据。
{
"0": {
"id": 2,
"sku": "SKU914",
"price": 1.0,
"special_price": 0.91,
"weight": 763,
"barcode": "0434120288572",
"created_at": "2020-01-31 14:39:53",
"updated_at": "2020-01-31 14:39:53"
},
"id": 1,
"sku": "SKU579",
"price": 22.8,
"special_price": 19.14,
"weight": 478459,
"barcode": "1390377688",
"created_at": "2020-01-31 14:34:59",
"updated_at": "2020-01-31 14:34:59"
}
我推送的第二个产品($product 2)在阵列之外。我该怎么做才能让它像"0": {}, "1": {}
DIEA
慕勒3428872
慕容森