first(); if (!$order) { return response()->json(['error' => 'Order not found'], 404); } try { // Generate invoice $invoicePath = InvoiceService::generateInvoice($order); // Get the full path from public disk $fullPath = storage_path('app/public/' . $invoicePath); Log::info('Invoice test:', [ 'order_number' => $orderNumber, 'stored_path' => $invoicePath, 'full_path' => $fullPath, 'file_exists' => file_exists($fullPath), ]); if (file_exists($fullPath)) { return response()->file($fullPath); } else { return response()->json([ 'error' => 'Invoice file not found', 'path' => $invoicePath, 'full_path' => $fullPath, ], 500); } } catch (\Exception $e) { Log::error('Invoice test error:', [ 'order_number' => $orderNumber, 'error' => $e->getMessage(), 'trace' => $e->getTraceAsString(), ]); return response()->json([ 'error' => 'Failed to generate invoice', 'message' => $e->getMessage() ], 500); } })->name('test-invoice');