Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel nova - use action to allow multiple download

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.

like image 694
Prafulla Kumar Sahu Avatar asked Jul 03 '19 18:07

Prafulla Kumar Sahu


1 Answers

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');
}
like image 127
Mister Verleg Avatar answered Nov 15 '22 08:11

Mister Verleg