Send invoices by email.
This commit is contained in:
@@ -9,10 +9,29 @@ use Illuminate\Http\Response;
|
||||
|
||||
class PdfController extends Controller
|
||||
{
|
||||
/**
|
||||
* Return an invoice as download for the specified resource.
|
||||
*/
|
||||
public function downloadInvoice(int $invoice_id): Response
|
||||
{
|
||||
return $this->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()])->stream();
|
||||
return Pdf::loadView('pdfs.invoice', ['invoice' => $invoice->load(['address', 'delivery']), 'options' => Option::optionsAsObject()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user