简体   繁体   中英

PDF as mail attachment - Laravel

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

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());
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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