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

bennettblack's avatar

Initiate download from Nova Action handle() ?

I'm trying to use maatwebsite/excel to download an export file from my Nova action. This should be very straightforward. However, the following does not work:

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {

        return Excel::download(new ShowOrderExport, 'test.csv');
    }

Alternatively, I can initiate the CSV export by putting the above return statement in its own route like:

Route::get('/reports/show-orders', function(){
        return Excel::download(new ShowOrderExport, 'test.csv');
    });

And using Action::redirect from the Action's handle method to call the route:

    /**
     * Perform the action on the given models.
     *
     * @param  \Laravel\Nova\Fields\ActionFields  $fields
     * @param  \Illuminate\Support\Collection  $models
     * @return mixed
     */
    public function handle(ActionFields $fields, Collection $models)
    {
        return Action::redirect('/reports/show-orders');
    }

Which initiates the download as expected. Why does the first solution not initiate the download?

0 likes
4 replies
neilstee's avatar

@bennettblack I think you have to store the excel file somewhere first and use Nova's Action::download($filePath) to download the file.

bennettblack's avatar

Yes, that's another solution. I'd really rather avoid doing that though.

1 like
internetbug256's avatar

I can't hit the nail with making an action to trigger the download. It doesn't work. I do generate the xls file in the storage folder, but then I can't make Nova to start the download. It silently goes back to the index, telling me that the action was completed. This is my action class:

    public function handle(ActionFields $fields, Collection $models)
    {
        $file = 'vessels.xlsx';
        Excel::store(new VesselsByFleetExport($models), $file);
        return Action::download(storage_path('app/'.$file), $file);
    }

Please or to participate in this conversation.