Delete Cart Items

This commit is contained in:
UronShrestha
2024-07-05 13:14:27 +05:45
parent 71944f3245
commit 4a512fa736
3 changed files with 24 additions and 9 deletions

View File

@ -130,7 +130,8 @@ class MainController extends Controller
public function cart()
{
$cartItems = DB::table('products')
->join('carts', 'carts.productId', '=', 'products.id')
// ->join('carts', 'carts.productId', '=', 'products.id')
->join('carts', 'carts.productId', 'products.id')
->select('products.name', 'products.price', 'products.picture', 'products.quantity as pQuantity', 'carts.*')
->where('carts.customerId', session()->get('id'))
->get();
@ -140,11 +141,6 @@ class MainController extends Controller
return view('cart', compact('cartItems'));
}
public function addToCart(Request $data)
{
if (session()->has('id')) {
@ -160,6 +156,15 @@ class MainController extends Controller
}
}
public function deleteCartItem($id)
{
$item = Cart::find($id);
$item->delete();
return redirect()->back()->with('success', 'Item deleted from cart successfully!');
}
public function checkout()
{
return view('checkout');