diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index 3b533f1..fcaeaf6 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -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'); diff --git a/resources/views/cart.blade.php b/resources/views/cart.blade.php index a297639..e1289fb 100644 --- a/resources/views/cart.blade.php +++ b/resources/views/cart.blade.php @@ -25,6 +25,13 @@
+ + @if (session()->has('success')) +
+ {{ session()->get('success') }} +
+ @endif + @@ -77,8 +84,8 @@ - + @endforeach diff --git a/routes/web.php b/routes/web.php index ddfca93..6dd753a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -11,6 +11,7 @@ Route::get('/blogDetails', [MainController::class, 'blogDetails']); Route::get('/cart', [MainController::class, 'cart']); Route::post('/addToCart', [MainController::class, 'addToCart']); +Route::get('/deleteCartItem/{id}', [MainController::class, 'deleteCartItem']); Route::get('/checkout', [MainController::class, 'checkout']); Route::get('/main', [MainController::class, 'main']);
-
{{ $item->name }}
-
Nrs {{ $item->price }}
+
{{ $item->name }} (Nrs {{ $item->price }})
+

Nrs. {{ $item->price * $item->quantity }}
+ +