diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index fcaeaf6..12b584c 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -163,6 +163,42 @@ class MainController extends Controller return redirect()->back()->with('success', 'Item deleted from cart successfully!'); } + // public function updateCartItem(Request $data, $id) + // { + // if (session()->has('id')) { + // $item = Cart::find($data->input('id')); + // $item->quantity = $data->input('quantity'); + // $item->save(); + // return redirect()->back()->with('success', 'Item updated successfully!'); + // } else { + // return redirect('/login')->with('error', 'Please login to update item!'); + // } + // } + + public function updateCartItem(Request $request, $id) + { + // dd($request->all()); + if (session()->has('id')) { + $item = Cart::find($id); + if ($item) { + $item->quantity = $request->input('quantity'); + $item->save(); + return redirect()->back()->with('success', 'Item updated successfully!'); + } else { + return redirect()->back()->with('error', 'Item not found!'); + } + } else { + return redirect('/login')->with('error', 'Please login to update item!'); + } + } + + + + + + + + public function checkout() diff --git a/resources/views/cart.blade.php b/resources/views/cart.blade.php index e1289fb..27e5a4d 100644 --- a/resources/views/cart.blade.php +++ b/resources/views/cart.blade.php @@ -43,38 +43,9 @@ + + {{-- - @foreach ($cartItems as $item) - - -
- -
- - - -
-
- {{ $item->name }} -
-
- Nrs {{ $item->price }} -
-
-
- - - -
- -
Nrs. {{ $item->price * $item->quantity }} - - - @endforeach - --}} - - @foreach ($cartItems as $item) @@ -93,13 +64,45 @@
Nrs. {{ $item->price * $item->quantity }} + + + + @endforeach + --}} + + @foreach ($cartItems as $item) + + +
+ +
+ + +
+
{{ $item->name }}
+
Nrs {{ $item->price }}
+
+
+
+ @csrf + + +
+
+ +
Nrs. {{ $item->price * $item->quantity }} + @endforeach + +
diff --git a/routes/web.php b/routes/web.php index 6dd753a..71867b9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -12,6 +12,8 @@ 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::post('updateCartItem/{id}', [MainController::class, 'updateCartItem'])->name("cart.update"); + Route::get('/checkout', [MainController::class, 'checkout']); Route::get('/main', [MainController::class, 'main']);