php - 删除购物车 laravel 7 中的产品
问题描述
我尝试使用 laravel 开发购物车,我在此链接中使用 laravel 购物车我的问题是我无法删除购物车中的产品,并且会得到这张图片
网页.php
Route::post('/cart/{rowId}', 'CartController@destroy')->name('cart.destroy');
购物车控制器.php
public function destroy($id)
{
\Cart::remove($id);
return back()->with('success', 'Item has been removed!');
}
index.blade.php
<form action="{{ route('cart.destroy', $item->rowId) }}" method="POST">
<button class="btn btn-sm btn-danger">Remove</button>
</form>
解决方案
使用此代码:
网页.php
Route::get('/cart/{rowId}', 'CartController@destroy')->name('cart.destroy');
购物车控制器.php
public function destroy($id) {
$cart = Cart::findOrFail($id);
$cart->delete();
return redirect()->route('')->with('success', 'Item has been removed!');
}
index.blade.php
<a href="{{ route('cart.destroy', $item->rowId) }}" class="" title="Remove Cart">
<i class="fa fa-trash"></i>
</a>
推荐阅读
- android - ViewPager 不显示内容 onResume
- internet-explorer-11 - 由于长时间运行的脚本,IE11 没有响应
- reactjs - reactjs图像不显示
- ios - 在 Objective C 中创建的访问对象
- android - 是否可以将背景颜色设置为 Card 元素标题(react-native-elements)?
- android - 如何在 textView 或 listView 中显示来自 wifiManager.connectionInfo 的 BSSID
- html - Html/css:如何使输入字段中的值由框分隔
- python - 如何将所有选择(例如,来自调查)作为列计数
- c - cairo / xlib 不更新窗口内容
- javascript - 渲染两个导航器