Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

michalis's avatar

dompdf not loading data to view

hi guys, im trying to use barryvdh/laravel-dompdf, everything works fine exept i cant load my data to the view to dynamically produce content, i keep getting 'Undefined variable: data'

here is my code:


 public function certificate($id)
    {
        $data = RegisteredProduct::findOrFail($id);

        $pdf = PDF::loadView('pdf.certificate', $data);
        return $pdf->download('certificate.pdf');
    }

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    </head>
    <body>
        {{ $data->id }}
    </body>
</html>

any ideas?

0 likes
2 replies
christopher's avatar

@Fruty Yep. Just tested it and its working with compact. Or if you use an array $pd = $pdf->loadView('pdf', array('data' => 'test')); and in your view $data .

Please or to participate in this conversation.