3

with an action I need to be able to download a file. How can I do?

with this code

return Action::download('https://example.com/invoice.pdf', 'Invoice.pdf');

a url must be passed, I would like to pass the path (ex. storage/folder/filename.xx)

Thank You

Sandro
  • 41
  • 2
  • 4

2 Answers2

0

Make a route that downloads the invoice.

Then Action::redirect('invoice') to that route


Route::get('invoice', function() {

    $path = auth()->user()->latestInvoice();

    return response()->download($path);
});
Brian Dillingham
  • 9,118
  • 3
  • 28
  • 47
0

You can use Storage::url() function. For example :

use Illuminate\Support\Facades\Storage;    
...    

class YourAction extends Action
{

    public function handle()
    {
        return Action::download(Storage::url('folder/filename.xxx'), 'Name.xxx');
    }
}

Note :

When using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.

Saumini Navaratnam
  • 8,439
  • 3
  • 42
  • 70