From 9d7478159f59d352ee2dba01bf9e10511758ce98 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Tue, 21 Jan 2025 02:51:07 +0800 Subject: [PATCH] added return ajax and fetch only can surf showavailable-carts --- app/Http/Controllers/BayaranController.php | 50 +++++++++++-------- public/js/miscellaneous/cart.js | 2 +- public/js/miscellaneous/navigation-trolley.js | 8 ++- resources/views/includes/home.blade.php | 10 +++- .../includes/main/footercontent.blade.php | 3 -- .../pembayaran/resit/resitportal.blade.php | 1 + 6 files changed, 47 insertions(+), 27 deletions(-) diff --git a/app/Http/Controllers/BayaranController.php b/app/Http/Controllers/BayaranController.php index 3874901..4546c9f 100644 --- a/app/Http/Controllers/BayaranController.php +++ b/app/Http/Controllers/BayaranController.php @@ -237,7 +237,7 @@ class BayaranController extends Controller $date = $current->toDateTimeString(); $payment_details = $this->CallableHttp - ->get('/api/transaction/online/express', ['billplz_id' => $request->billplzid]) + ->get('/api/transaction/online/express', ['billplz_id' => $request->billplzid,'norujukan' => $request->norujukan]) ->json(); $cawangan_info = $this->CallableHttp @@ -508,28 +508,38 @@ class BayaranController extends Controller return $exist_carts; } - public function UserCheckCarts(){ - $exist_carts = PersonalCarts::where('ic_no', Auth::user()->icno) - ->where('user_id', Auth::user()->id) - ->where(function ($query) { - $query->where('status_pkb', 'PENDING') - ->orWhere('status_koop', 'PENDING'); - }) - ->first(); - - return response()->json($exist_carts); - } - - public function removeCarts(){ - $exist_carts = PersonalCarts::where('ic_no', Auth::user()->icno) - ->where('user_id', Auth::user()->id) - ->first(); + public function UserCheckCarts(Request $request){ + if($request->ajax() || $request->expectsJson()){ + $exist_carts = PersonalCarts::where('ic_no', Auth::user()->icno) + ->where('user_id', Auth::user()->id) + ->where(function ($query) { + $query->where('status_pkb', 'PENDING') + ->orWhere('status_koop', 'PENDING'); + }) + ->first(); - if ($exist_carts) { - $exist_carts->delete(); + return response()->json($exist_carts); + }else{ + return redirect()->route('buffer'); } - return response()->json($exist_carts); + + } + + public function removeCarts(Request $request){ + if($request->ajax() || $request->expectsJson()){ + $exist_carts = PersonalCarts::where('ic_no', Auth::user()->icno) + ->where('user_id', Auth::user()->id) + ->first(); + + if ($exist_carts) { + $exist_carts->delete(); + } + + return response()->json($exist_carts); + }else{ + return redirect()->route('buffer'); + } } public function serviceCallHttp($company){ diff --git a/public/js/miscellaneous/cart.js b/public/js/miscellaneous/cart.js index 1f97022..97e0708 100644 --- a/public/js/miscellaneous/cart.js +++ b/public/js/miscellaneous/cart.js @@ -71,7 +71,7 @@ let deleteCarts = () => { if(loader) loader.classList.remove('d-none'); - fetch('/deletecarts') + fetch('/deletecarts', {method: 'GET', headers: {'Content-Type': 'application/json','Accept': 'application/json'}}) .then(response => { if (!response.ok) { throw new Error('HTTP error ' + response.status); diff --git a/public/js/miscellaneous/navigation-trolley.js b/public/js/miscellaneous/navigation-trolley.js index 6dd10b4..6116d88 100644 --- a/public/js/miscellaneous/navigation-trolley.js +++ b/public/js/miscellaneous/navigation-trolley.js @@ -1,6 +1,12 @@ async function fetchCartCount() { try { - const response = await fetch('/showcarts-available'); + const response = await fetch('/showcarts-available', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + }); if (!response.ok) { throw new Error('Failed to fetch cart count'); diff --git a/resources/views/includes/home.blade.php b/resources/views/includes/home.blade.php index 52fe03a..da9b7af 100644 --- a/resources/views/includes/home.blade.php +++ b/resources/views/includes/home.blade.php @@ -209,7 +209,7 @@ const loader = document.getElementById('load-arrahn'); loader.classList.remove('d-none'); if (result.isDenied) { - let remove_carts = fetch('/deletecarts') + let remove_carts = fetch('/deletecarts', {method: 'GET', headers: {'Content-Type': 'application/json','Accept': 'application/json'}}) .then(response => { if (!response.ok) { throw new Error('HTTP error ' + response.status); @@ -227,7 +227,13 @@ const checkCarts = async () => { try { - const response = await fetch('/showcarts-available'); + const response = await fetch('/showcarts-available', { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + }); if (!response.ok) { throw new Error('HTTP error ' + response.status); diff --git a/resources/views/includes/main/footercontent.blade.php b/resources/views/includes/main/footercontent.blade.php index ab9ce61..c8b671f 100644 --- a/resources/views/includes/main/footercontent.blade.php +++ b/resources/views/includes/main/footercontent.blade.php @@ -74,9 +74,6 @@ {{-- --}} -