laravel nova download file from path

Viewed 1948

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

2 Answers

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);
});

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.

Related