defaultHostWorkspace(); if (! $workspace || $invoice->workspace_id !== $workspace->id) { abort(403, 'You do not have access to this invoice.'); } // Only allow downloading paid invoices if (! $invoice->isPaid()) { abort(403, 'This invoice cannot be downloaded yet.'); } // Use the download method from InvoiceService return $this->invoiceService->downloadPdf($invoice); } /** * View invoice in browser. */ public function view(Request $request, Invoice $invoice): Response { // Verify the invoice belongs to the user's workspace $user = Auth::user(); if (! $user instanceof User) { abort(403, 'Unauthorised'); } $workspace = $user->defaultHostWorkspace(); if (! $workspace || $invoice->workspace_id !== $workspace->id) { abort(403, 'You do not have access to this invoice.'); } // Generate PDF and get the content $path = $this->invoiceService->getPdf($invoice); $content = Storage::disk(config('commerce.pdf.storage_disk', 'local'))->get($path); return response($content, 200, [ 'Content-Type' => 'application/pdf', 'Content-Disposition' => 'inline; filename="invoice-'.$invoice->invoice_number.'.pdf"', ]); } }