Php Laravel 5.1是否可以在我的控制器中循环视图?
我正在使用laravel/dom pdf生成发票。问题是我有500个帐户要生成,我设法将数据传递到我的视图并循环它。但是我在保存pdf时遇到了问题。因为保存的pdf代码在我的控制器中 TestpdfControllerPhp Laravel 5.1是否可以在我的控制器中循环视图?,php,pdf,laravel-5.1,Php,Pdf,Laravel 5.1,我正在使用laravel/dom pdf生成发票。问题是我有500个帐户要生成,我设法将数据传递到我的视图并循环它。但是我在保存pdf时遇到了问题。因为保存的pdf代码在我的控制器中 TestpdfController $pdf = PDF::loadView('invoices.viewinvoicepdf'); $pdf->save(path/to/save'/'.$inv->accountid.'.pdf'); // problem here is that i cannot
$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.
我的第二个选项放在foreach中,但我认为它效率不高,因为它会因为foreach而渲染500次视图
foreach($invoices as $inv){
$pdf = PDF::loadView('invoices.viewinvoicepdf',compact('invoices'));
$pdf->save(path/to/save'/'.$inv->accountid.'.pdf');
}
如何修复此问题?如果您需要单独保存每个PDF文件,我认为您除了使用循环之外别无选择。我假设您的视图文件中有一个循环。您可以在控制器中移动该循环,并让视图文件只接受一张
发票