In laravel Nova 2.0
To initiate a file download after the action is executed, you may use the Action::download method. The download method accepts the URL of the file to be downloaded as its first argument, and the desired name of the file as its second argument:
return Action::download('https://example.com/invoice.pdf', 'Invoice.pdf');
in Action handle method
public function handle(ActionFields $fields, Collection $models)
{
foreach ( $models as $model ) {
return Action::download($model->document_link, $model->document_title);
}
}
now this will download the last one in loop, how to allow download all in the loop?
Update
One option will be using Zipper or something to create zip of all the downloadable files selected and then download it, but I would like it if we can allow a queue of downloads.
I don't believe it is possible to download multiple files using
return Action::download()
A work around could be to create a zipped archive containing all files and present this archive example:
public function handle(ActionFields $fields, Collection $models)
{
foreach ( $models as $model ) {
$this->addTozip($model) // some function to build an archive
}
return Action::download('https://example.com/invoice.zip', 'Invoice.zip');
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With