我尝试使用 Laravel 开发购物车,我在此 link 中使用 Laravel 购物车,我的问题是我无法删除购物车中的产品,但会得到此 image
web.php
Route::post('/cart/{rowId}', 'CartController@destroy')->name('cart.destroy');
CartController.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>
答案 0 :(得分:0)
使用此代码:
web.php
Route::get('/cart/{rowId}', 'CartController@destroy')->name('cart.destroy');
CartController.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>