From 9a6ca49ad7dab267c7c4c39c5c946c7b59f92705290c1ae2730953307b842c1e Mon Sep 17 00:00:00 2001 From: Abhishek Mali Date: Fri, 13 Mar 2026 20:19:34 +0530 Subject: [PATCH] user order controller update for show view data --- .../Controllers/user/UserOrderController.php | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/app/Http/Controllers/user/UserOrderController.php b/app/Http/Controllers/user/UserOrderController.php index 0477dc7..f58a935 100644 --- a/app/Http/Controllers/user/UserOrderController.php +++ b/app/Http/Controllers/user/UserOrderController.php @@ -139,26 +139,36 @@ public function orderDetails($order_id) ], 401); } - // Find invoice for this customer and container + // Find container first + $container = \App\Models\Container::find($order_id); + + if (!$container) { + return response()->json([ + 'success' => false, + 'message' => 'Container not found' + ], 404); + } + + // Find invoice belonging to this user for this container $invoice = \App\Models\Invoice::where('customer_id', $user->id) - ->where('container_id', $order_id) - ->with(['items', 'container']) + ->where('container_id', $container->id) + ->with(['items']) ->first(); if (!$invoice) { return response()->json([ 'success' => false, - 'message' => 'Order not found' + 'message' => 'Order not found for this user' ], 404); } return response()->json([ 'success' => true, 'order' => [ - 'container_id' => $invoice->container->id ?? null, - 'container_number' => $invoice->container->container_number ?? null, - 'container_date' => $invoice->container->container_date ?? null, - 'status' => $invoice->container->status ?? null, + 'container_id' => $container->id, + 'container_number' => $container->container_number, + 'container_date' => $container->container_date, + 'status' => $container->status, 'invoice_id' => $invoice->id, 'items' => $invoice->items ]