Well, you shouldn't return the file then. Instead, you can use the Storage facade to store the file wherever you want.
Storage::put(public_path('files/file.csv'), $contents);
Documentation: https://laravel.com/docs/9.x/filesystem#storing-files
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i have an dynamic URL, and by hitting this url, a csv file is downloaded into downloads folder of system. but i want to write logic into laravel so when we call this url the file must be downloaded into storage or public directory. so i can play around with this file.
return Redirect::to($url);
i tried with this method, but as i mentioned, the file will be downloaded, but in downloads folder of my computer. i want to download in storage folder of my laravel project.
Please or to participate in this conversation.