不保存到数据库
帮助我理解我的错误
控制器
public function store(Request $request) { $item = Cart::where('product_id', $request->product_id); if ($item->count()) { $item->increment('quantity'); $item = $item->first(); } else { $item = Cart::forceCreate([ 'product_id' => $request->product_id, 'quantity' => 1, ]); } return response()->json([ 'quantity' => $item->quantity, 'product' => $item->product ]); }
商店
addProductToCart (product, quantity) { axios.post('http://127.0.0.1:8000/api/cart', { product_id: product.id, quantity }) },
当点击addItems(例如)按钮时,项目不会添加到数据库
P粉3233748782024-03-23 10:05:16
我的突变恰好位于错误的模块中
add_to_cart(state, {product, quantity}) { let productInCart = state.cart.find(item => { return item.product.id === product.id; }); if (productInCart) { productInCart.quantity += quantity; return; } state.cart.push({ product, quantity }) },