DOMPDF loadView() error - undefined variable: data

后端 未结 2 991
旧时难觅i
旧时难觅i 2021-01-17 18:50

I\'m currently trying to incorporate the DOMPDF Wrapper for Laravel into my project, however I\'m having troble figuring out how to pass a variable into the PDF template.

相关标签:
2条回答
  • 2021-01-17 19:19

    The loadView method you are using is going to use the extract method before passing the data to the views. This method extracts all the array elements, and creates variables for them based on the key of the element

    This means that your array keys are going to be your variable names, ie $name and not $data->name. This is fairly standard in laravel, for example when using Blade Views.

    http://php.net/manual/en/function.extract.php

    0 讨论(0)
  • 2021-01-17 19:26

    Use compact('data') instead of $data.

    Example:

    $pdf = \PDF::loadView('productType.invoice', compact('data'));
    
    0 讨论(0)
提交回复
热议问题