我正在創建一個 Laravel 電子商務網站,并且正在使用 Gloudemans\Shoppingcart\ 庫。我在使用“添加到購物車”按鈕時遇到問題。我再解釋一下!我有一個 singleProduct.blade.php 文件,它從控制器調用產品信息:這是將數據從數據庫傳遞到視圖的函數:public function show($name){ $iamlush = iamlush::where('name', $name)->firstOrFail(); return view('singleProduct')->with('product', $iamlush);}這是單個產品文件:<div class="contentContainer"> <div class="rowContainer text-center"> <div class="productImgContainer"> <img src="{{ asset('img/iamlush/shop/'.$product->img) }}" class="productImg"> </div> <div class="productInfoContainer"> <div class="text-center"> <div class="productLogoContainer"> <img src="{{ asset('img/logo/'.$product->productLogo) }}" class="logoContainer"> </div> <h3>{{ $product->name }}</h3> <h5>{{ $product->priceFormat() }}</h5> </div> <p class="descriptionContainer"> {{ $product->description }} </p> <div class="rowContainer"> <div class="iconContainer"> <img src="{{ asset('img/productPage/productInfo.png') }}" class="icons"> </div> <div class="iconContainer"> <img src="{{ asset('img/productPage/paymentMethods.jpg') }}" class="icons"> </div> </div> <form action="{{ route('cart.store') }}" method="POST" class="formContainer"> @csrf <input type="hidden" name="id" value="{{ $product->id }}"> <input type="hidden" name="name" value="{{ $product->name }}"> <input type="hidden" name="price" value="{{ $product->price }}"> <div class="BtnContainer"> <button type="submit" class="btnCart">Add To Cart</button> </div> </form> </div> </div></div>“添加到購物車”向“cart.store”發送 POST 請求,這是 web.php:Route::post('/cart', 'CartController@store')->name('cart.store');
1 回答

慕萊塢森
TA貢獻1810條經驗 獲得超4個贊
首先,嘗試調試您的查詢結果
dd($iamlush)
如果有null,檢查你的數據庫?您有該名稱的任何記錄嗎?可能有兩個原因
您沒有此情況的任何記錄
你的模型有錯誤
- 1 回答
- 0 關注
- 118 瀏覽
添加回答
舉報
0/150
提交
取消