I want to create a PDF using the barryvdh/laravel-dompdf package and send this with an email as attachment.
The code I have now is:
$pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur));
Mail::queue('emails.factuur', array('factuur' => $factuur), function($message) use ($pdf)
{
$message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp');
$message->attach($pdf->output());
});
But now I get the following error:
Serialization of 'Closure' is not allowed
The Dompdf library can be used to convert HTML to PDF using PHP. The Dompdf is a PHP library that helps to convert HTML to PDF document. If your application is built with Laravel, the Dompdf library is the best option to create a PDF file and add HTML content to PDF document.
You can only send serializable entities to the queue. This includes Eloquent models etc. But not the PDF view instance. So you will probably need to do the following:
Mail::queue('emails.factuur', array('factuur' => $factuur), function($message)
{
$pdf = PDF::loadView('layouts.factuur', array('factuur' => $factuur));
$message->to(Input::get('email'), Input::get('naam'))->subject('Onderwerp');
$message->attach($pdf->output());
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With