Laravel-snappy: Passing variables.

Created on 11 Apr 2017  路  2Comments  路  Source: barryvdh/laravel-snappy

Hi,

I have a function from within my controller (projectController) from which I call PDF::loadView in the hope of passing the view with a variable ($projects) to snappy.

My code is as

`public function exportPdf()
{
//$snappy = App::make("snappy.pdf");
//$snappy->generate("http://www.github.com", "/tmp/github2.pdf");
//
//$pdf=App::make("snappy.pdf.wrapper");
//$pdf->loadHTML("testing");
//

   $projects = Project::all();
   $projects->toArray();      
    $pdf = PDF::loadView("projects.index", $projects);
    return $pdf->download("invoice.pdf");

}`

The two commented out bits of code above work fine I am getting errors when passing a variable to loadView. The error is as follows.

`Whoops, looks like something went wrong.

2/2
ErrorException in 815b10a9263616cef7f18e26d46f3bd36ae10e37.php line 8:
Undefined variable: projects (View: D:\git\portal\resources\views\projects\index.blade.php)
in 815b10a9263616cef7f18e26d46f3bd36ae10e37.php line 8
at CompilerEngine->handleViewException(object(ErrorException), "1") in PhpEngine.php line 44
at PhpEngine->evaluatePath("D:\git\portal\storage\framework\views/815b10a9263616cef7f18e26d46f3bd36ae10e37.php", array("__env" => object(Factory), "app" => object(Application), "errors" => object(ViewErrorBag), array("id" => "7", "code" => "typical project",
<--- Section deleted for brevity -->
, "updated_at" => "2017-04-10 05:53:16", "created_at" => "2017-04-07 01:36:34", "submitterId" => "22"))) in CompilerEngine.php line 59`

The $projects array is being passed but it doesn"t seem like it is being recognised by the view? I"m I doing this the wrong way? I know variables can be passed to it.

Any hep would be greatly appreciated,
Thanks,
Bobbie.

Edit: Sorry for the formatting the output didn"t seem to format very well.

stale

Most helpful comment

Same as a normal view, pass an array with data.

All 2 comments

Same as a normal view, pass an array with data.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.
Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/KnpLabs/snappy instead. When having doubts, please try to reproduce the issue with just snappy.
If you believe this is an actual issue with the latest version of laravel-snappy, please reply to this issue so we can investigate further.
Thank you for your contribution! Apologies for any delayed response on our side.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

medspec picture medspec  路  4Comments

closca picture closca  路  7Comments

larsemil picture larsemil  路  5Comments

vitorarjol picture vitorarjol  路  4Comments

austenc picture austenc  路  7Comments