它尝试了此代码,但无法正常工作。问题是什么?我该如何解决?
--fork-point
传递给Barryvdh \ DomPDF \ PDF :: __ construct()的参数1必须是 Dompdf \ Dompdf的实例,App \ Invoice的实例,在 C:\ xampp \ htdocs \ shopping-cart \ app \ Http \ Controllers \ InvoiceController.php
答案 0 :(得分:-1)
您可以直接通过以下方式使用立面:
use use Barryvdh\DomPDF\Facade as PDF;
...
public function PDF(Invoice $invoice)
{
$items = unserialize($invoice->items);
$fileName =$invoice->invoice_code;
$pdf = PDF::loadView('invoice.pdf', compact('invoice', 'items'));
return $pdf->stream($fileName . '.pdf');
}
of以别名添加到config.php
后:
config.php
'aliases' => [
...
'PDF' => Barryvdh\DomPDF\Facade::class,
],
控制器
//no use needed
...
public function PDF(Invoice $invoice)
{
$items = unserialize($invoice->items);
$fileName =$invoice->invoice_code;
$pdf = \PDF::loadView('invoice.pdf', compact('invoice', 'items'));
return $pdf->stream($fileName . '.pdf');
}