@bennettblack I think you have to store the excel file somewhere first and use Nova's Action::download($filePath) to download the file.
Aug 19, 2021
4
Level 6
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?
Please or to participate in this conversation.