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

Shiva's avatar
Level 5

Getting Dompdf to show the view

I'm trying to get Dompdf to display the view that I have. This is what I have

use Dompdf\Dompdf;

class ProductController extends Controller
{

    public function pdf($id)
    {
        $product= Product::find($id);
        $pdf = \PDF::loadView('product_show', $product);
        return $pdf->stream();

    }
}

and the error that I get is

ErrorException in e58b6c236fa516aa89d08c30940bd63390feda2d.php line 1: 
Undefined variable: product(View: C:\wamp\www\products\resources\views\product_show.blade.php)
0 likes
3 replies
ohffs's avatar
ohffs
Best Answer
Level 50

Maybe

$pdf = \PDF::loadView('product_show', compact('product'));
ohffs's avatar

No worries - glad that fixed it :-)

Please or to participate in this conversation.