简体   繁体   English

Laravel使用domPDF

[英]Laravel using domPDF

I want to download a blade. 我要下载刀片。 I am using dompdf. 我正在使用dompdf。

public function download($id)
{
    $booking=Booking::where('id',$id)->first();
    $pdf = PDF::loadView('pages.booking.bookingdetails',$booking);
    return $pdf->download('bookingdetails.pdf');
}

bookingdetails.blade.php bookingdetails.blade.php

<div class="container">
    <div class="card">
        <div class="card-header">
            Invoice  # {{$booking->id}}
            <strong>01/01/01/2018</strong>
            <span class="float-right"> <strong>Status:</strong> Pending</span>
        </div>
    </div>
</div>

So what I want to do is passing the $booking variable from the method and send to the view. 所以我要做的是从方法中传递$booking变量并发送到视图。 Then download it as a pdf file. 然后将其下载为pdf文件。

But the error is: 但是错误是:

"Undefined variable: booking “未定义变量:预订

我在黑暗中拍摄,不是吗:

$pdf = PDF::loadView('pages.booking.bookingdetails', ['booking' => $booking]);

您需要将数组作为第二个参数传递给带有booking索引名称的视图,因此请尝试以下操作:

$pdf = PDF::loadView('pages.booking.bookingdetails',['booking' => $booking]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM