Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

michalis's avatar

how to use Storage::download()

this is my method

    public function download($id)
    {
        $file = File::find($id);
        $link = json_decode($file->link);

        return Storage::download('storage/' . $link[0]->download_link);
    }   

but it wont download the file, I get a file not found exeption

League \ Flysystem \ FileNotFoundException
File not found at path: storage/files/May2019/caAsV09m4I5FZdOmALIZ.png

the path i correct though, not sure why its not working

when I do it as a link on the front end it works, but doing it from a method in the backend does not work for some reason

am I using the function correctly?

0 likes
7 replies
JAY_CHAUHAN's avatar

It may caching issue, clear the laravel cache by following command

php artisan cache:clear

php artisan route:cache

php artisan config:cache

php artisan view:clear

or if still this not work then try

return Storage::download("your path after storage/App", $link[0]->download_link);

i hope this will work for you.

2 likes
vandan's avatar

@JAY_CHAUHAN - can you help me bro my question

how to pass id into middleware in laravel

1 like
michalis's avatar

@JAY_CHAUHAN - clearing the cache didnt work, as for the other one i did this

return Storage::download('storage', $link[0]->download_link);

but i get

The filename and the fallback cannot contain the "/" and "\" characters.
JAY_CHAUHAN's avatar

@michalis please send me what contains a $link[0]->download_link

This is some id or anything text

also send where is your file in storage folder (extact location like storage->public->abc.txt etc) .

1 like
michalis's avatar

@JAY_CHAUHAN -

return Storage::download($link);

in this code, link is

C:/Users/com2go/Desktop/code/social_manager/public/storage/files/May2019/4ZLCxnK7Py2J1NpQTlS9.cs

and the path of the file on the hard drive is

C:/Users/com2go/Desktop/code/social_manager/public/storage/files/May2019/4ZLCxnK7Py2J1NpQTlS9.css
michalis's avatar
michalis
OP
Best Answer
Level 5

i ended up using response()->download(file)

1 like

Please or to participate in this conversation.