$user]); } public function addToCart(Product $product, Request $request) { $user = Auth::user(); $user->cart()->syncWithoutDetaching([$product->uuid]); $quantity = $request->validate([ 'quantity' => 'numeric|min:1' ])["quantity"] ?? 1; $pivot = $user->cart()->findOrFail($product->uuid)->pivot; $pivot->quantity = $quantity; $pivot->save(); return back(); } public function removeFromCart(Product $product) { $user = Auth::user(); $user->cart()->detach($product); return back(); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Product $product * @return \Illuminate\Http\Response */ public function update(Request $request, Product $product) { $product->fill($request->all()); $product->save(); return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully"); } /** * Remove the specified resource from storage. * * @param \App\Models\Product $product * @return \Illuminate\Http\Response */ public function destroy(Product $product) { $product->delete(); return redirect()->route("product.index"); } }