fields['show_course_cart'] ?? true) === false) { abort(404); } $coupon = null; $couponCode = $request->input('coupon'); if (!empty($couponCode)) { $coupon = $this->couponService->getCoupon($couponCode); if (!$coupon) { return back()->with('error', 'This coupon is not valid.'); } if (!$this->couponService->isCouponValid($coupon)) { return back()->with('error', 'Ops! coupon is expired.'); } } $cart = $this->cartService->getCartItems(Auth::user()->id); $calculatedCart = $this->cartService->calculateCart($cart, $coupon); return Inertia::render('cart/index', [ 'cart' => $cart, 'coupon' => $coupon, ...$calculatedCart, ]); } /** * Store a newly created resource in storage. */ public function store(Request $request) { $system = app('system_settings'); if (($system?->fields['show_course_cart'] ?? true) === false) { abort(404); } $this->cartService->addToCart(Auth::user()->id, $request->course_id); return redirect(route('course-cart.index'))->with('success', 'Course added to cart successfully.'); } /** * Update the specified resource in storage. */ public function update(Request $request, CourseCart $courseCart) { $system = app('system_settings'); if (($system?->fields['show_course_cart'] ?? true) === false) { abort(404); } $this->cartService->clearCart(Auth::user()->id); return back()->with('success', 'Cart updated successfully.'); } /** * Remove the specified resource from storage. */ public function destroy($course_cart) { $system = app('system_settings'); if (($system?->fields['show_course_cart'] ?? true) === false) { abort(404); } $this->cartService->removeFromCart(Auth::user()->id, $course_cart); return back()->with('success', 'Course removed from cart successfully.'); } }