laravel-dompdf icon indicating copy to clipboard operation
laravel-dompdf copied to clipboard

open() argument #1 ($filename) must not contain any null bytes

Open MyNameIsDVL opened this issue 1 year ago • 1 comments

This is my Service

use Barryvdh\DomPDF\Facade\Pdf;

class PdfService
{
    public function __construct()
    {}

    public static function voucher(Voucher $voucher)
    {
        $data = [
            'total_amount' => $voucher->amount,
            'code' => $voucher->code
        ];

        return Pdf::loadView('pdf.voucher', $data)->stream('voucher_'.$voucher->code.'.pdf');
    }
}

My markdown mail:

    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
        $attachments = array();
        foreach ($this->vouchers as $voucher) {
            array_push($attachments, PdfService::voucher($voucher));
        }
        return $this->markdown('mail.voucher', ['vouchers'=>$this->vouchers])->subject('Oto Twój voucher')->attachMany($attachments);
    }

What am I doing wrong? Thanks

MyNameIsDVL avatar Jan 29 '24 14:01 MyNameIsDVL

Seems like argument #1 ($filename) contains null bytes 😄😄

Also you are adding Response class to attachMany, you must attach only the output

->attachData($pdf->output(), 'voucher_'.$voucher->code.'.pdf')

parallels999 avatar Jan 29 '24 15:01 parallels999