Laravel – Attach PDF file into a Mail

laravel

I try to attach a pdf file from a view wish is working in PDF. but when i try to attach this as a PDF file into an email , i get

Swift_IoException in FileByteStream.php line 144: Unable to open file
for reading [HTTP/1.0 200 OK Cache-Control: no-cache, private
Content-Disposition: attachment; filename="invoice.pdf" Content-Type:
application/pdf

Someone know where i am doing it wrong ? thanks a lot in advance

Here my controller :

public function build()
{

    $federation = Structure::where('id' , '1')->first();
    $structure = Structure::where(['id' => $this->order->structure_id])->first();
    $order = $this->order;

    $url = url('/cotisationstructure/'.$this->order->id);

    $pdf = app('dompdf.wrapper');
    $pdf->loadView('cotisation_structure.facturePDFsingle', compact('order' , 'structure' , 'federation'));

    return $this->markdown('email.commande' ,compact('federation' , 'structure' , 'url'))
        ->subject('Nouvelle Achat de Licences sur FFRXIII Licences & Compétitions')
        ->attach($pdf->download('invoice.pdf'));
}

Best Answer

You need to give filename as string in attach function. For more check here : https://laravel.com/docs/5.4/mail#attachments

Related Topic