Just tried the snippet above and have it working.
At first I thought on maybe you got the file on the wrong path, as usually user files are stored in./storage/app ($path = storage_path('app/'. $filename);) and not just at ./storage.
But I tried with a file in both paths and it works.
The only thing I can think of is broken dependencies.
To test it out:
- remove you project's
./vendorfolder. - Run
composer installfrom a terminal at your project's root folder. - Remove any
.phpfile from this folder:./bootstrap/cacheinside your project - Try downloading the file again.
Another thing that just crossed my mind is if you could have any middleware that manipulates the response.
If you can please run:
php artisan route:list --path=download
Where you should replace download by whatever the route path that runs this code is. For example, if this code is run on a route with a path /admin/users/{user}/profile/report you should run:
php artisan route:list --path=admin/users/{user}/profile/report
And post the results.
Note that I didn't include the route's first forward-slash.