buildInvoicePdf($invoice_id)->stream(); } /** * Return a rendered pdf invoice as string to build an email attachment from it for the specified resource. */ public function attachInvoice(int $invoice_id): string { return $this->buildInvoicePdf($invoice_id)->output(); } /** * Render the pdf view for the given invoice. */ protected function buildInvoicePdf(int $invoice_id): \Barryvdh\DomPDF\PDF { $invoice = Invoice::find($invoice_id); return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => Option::optionsAsObject()]); } }