Laravel:__construct()必须是Dompdf \ Dompdf的实例

时间:2019-11-01 13:32:04

标签: php laravel dompdf

它尝试了此代码,但无法正常工作。问题是什么?我该如何解决?

--fork-point
  

传递给Barryvdh \ DomPDF \ PDF :: __ construct()的参数1必须是       Dompdf \ Dompdf的实例,App \ Invoice的实例,在       C:\ xampp \ htdocs \ shopping-cart \ app \ Http \ Controllers \ InvoiceController.php

1 个答案:

答案 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');
}