If you are using the Laravel Excel library take a look at the FromArray examples here. You can do the same with FromCollection just add a constructor and pass the data in.
Excel exporting
Hi all,
I am creating a report which also has a web view showing exactly the same data I want to export. Is there a way I can feed the same data collection to the Export class via a form or URL instead of running a new SQL query to get the same data on the Export class?
@tudosm you can't pass the $invoices from the view to the controller unless you submit them through a form.
Before you display the invoices to the view, you can however store the excel file to the storage, and then use just the exported file for the download. You won't have to query the database again.
And this is how you export to disk. https://docs.laravel-excel.com/3.1/exports/store.html
Please or to participate in this conversation.