// Controller method to download the PDF invoice
// It builds the PDF on the fly from the Blade View
// Trait "Documents" is important, see its content below
use App\Traits\Documents;
class Invoices extends Controller
{
use DateTime, Currencies, Documents, Uploads;
public function pdfInvoice(Document $invoice, Request $request)
{
$view = view($invoice->template_path, compact('invoice', 'currency_style'))->render();
$html = mb_convert_encoding($view, 'HTML-ENTITIES', 'UTF-8');
$pdf = app('dompdf.wrapper');
$pdf->loadHTML($html);
$file_name = $this->getDocumentFileName($invoice);
return $pdf->download($file_name);
}
}