Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

tnort's avatar
Level 4

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?

0 likes
3 replies
tnort's avatar
Level 4

@Nakov, I used it successfully in multiple places as such:

public function collection()
    {
        return Invoice::all();
    }

But what I need to do is basically on the view I have a variable $invoices which already has all invoices. What I want to do is to pass that variable $invoices from the view to the controller and then further call the Laravel Excel with that collection of invoices by providing the $invoices to the constructed and hence to download the export.

Simply put I want to send a collection or array from a view to a controller.

Nakov's avatar
Nakov
Best Answer
Level 73

@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

1 like

Please or to participate in this conversation.