gpt4 book ai didi

php - dompdf 不从 Laravel 8 和 Livewire View 下载 PDF

转载 作者:行者123 更新时间:2023-12-04 01:07:05 24 4
gpt4 key购买 nike

我正在使用 dompdf在我的 Laravel v8.26.1 应用程序中。我也在使用 Laravel Livewire v1.3.5。
我可以查看在 Livewire 之外下载 pdf 的 View ,但似乎无法让它在 Livewire View 中工作。我已经尝试了我能想到的所有配置,但一直遇到障碍。我要么得到一个 Undefined variable: workorder错误,或者根本没有错误,但也没有下载。
路线

...
Route::livewire('/workorder/{workorder}/print', 'admin.workorders.printer')->name('admin.workorder.print')->layout('layouts.admin');
...
livewire/admin/workorders/print.blade
...
<div>
<button wire:click="generatePDF({{$workorder->id}})">Create PDF</button>
</div>
...
livewire/admin/workorders/printer.php
...
use Barryvdh\DomPDF\Facade as PDF;
...
public function generatePDF($id)
{
$record = Workorder::find($id);
$data = [
'project_id' => $record->project_id,
'project_name' => $record->project_name,
'customer_id' => $record->customer_id,
'generator_id' => $record->generator_id,
'workorder_po_number' => $record->workorder_po_number,
'workorder_number' => $record->workorder_number,
'prevailing_wage' => $record->prevailing_wage,
];
$pdf = PDF::loadView('livewire.admin.workorders.print', $data);
return $pdf->download('demo.pdf');
}

最佳答案

Here you go ,刚发现这个。把我修好。我唯一需要改变的是 $viewData变量,我只需要把它变成一个数组 - ['viewData' => $viewData]然后我可以在我看来访问它。
这是链接发生故障时的代码:

$pdfContent = PDF::loadView('view', $viewData)->output();
return response()->streamDownload(
fn () => print($pdfContent),
"filename.pdf"
);

关于php - dompdf 不从 Laravel 8 和 Livewire View 下载 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66082553/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com