vendredi 16 octobre 2015

Laravel 5.1 Is it possilbe to loop the view in my controller?

I am using laravel/dom-pdf to generate invoices. the problem is that I have 500 accounts to generate,I manage to pass the data to my views and loop it.but I am having problem in saving the pdf. because the saving pdf code is in my controller..

TestpdfController

$pdf = PDF::loadView('invoices.viewinvoicepdf');
$pdf->save(path/to/save'/'.$inv->accountid.'.pdf'); // problem here is that i cannot grab the accountid for each user and only the last account will be created.

my second option is put inside to foreach, but I think it is not effecient because it renders the views 500 times because of the foreach.

foreach($invoices as $inv){
  $pdf = PDF::loadView('invoices.viewinvoicepdf',compact('invoices'));
    $pdf->save(path/to/save'/'.$inv->accountid.'.pdf');
}

can anyone suggest me how to fix this.

Thank you in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire