我正在嘗試創建一個系統,用戶可以在其中將多個專案添加到“購物車”并一次全部下載。我正在關注一個youtube視頻并使用這個購物車包。我在商品的每一行中創建了一個簡單的“添加到購物車”按鈕,該按鈕將發送商品的 ID,并嘗試使用以下命令在同一頁面上顯示購物車中的商品數量:
Cart({{ \Gloudemans\Shoppingcart\Facades\Cart::content()->count() }})。單擊一次后,數字將增加到 1,但盡管嘗試在其中添加其他專案,但仍會保留在那里。請問我做錯了什么?
這是我的blade.php 的片段:
<td>
<a href="{{ url('model/download/'.$item->id) }}"class="btn btn-app btn-success"><i class="fa fa-save"></i>Download</a>
<a href="{{ url('model/view/'.$item->model_name) }}"hljs-string">"><i hljs-string">"></i>View</a>
<form action="{{ route('model.cart') }}" method="POST">
@csrf
<input type="hidden" value="{{$item->id}}" name="item_id">
<button type="submit" hljs-string">" ><i hljs-string">"></i>Add to cart</button>
{{-- <a href="{{ url('model/addCart/'.$item->id) }}"hljs-string">" ><i hljs-string">"></i>Add to cart</a> --}}
</td>
這是我的控制器:
public function addCart(Request $request){
$item=Item::findOrFail($request->input('item_id'));
Cart::add(
$item->id,
'NULL',
1,
1,
);
return Redirect()->back();
}
uj5u.com熱心網友回復:
您是否嘗試過{{Cart::count()}}顯示{{Cart::content()->count()}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/489846.html
