siusiak1000's avatar

Return response download and return back

Hey! I wanted to return

            $download = response()->download($filePath, $fileName, $headers);
            $redirect = back()->with('success', 'THX!');

But I do not know how to do it. I would have to do a double return. Anyone have any idea? Thanks!

0 likes
1 reply
Talinon's avatar

You can only have 1 response, so it's impossible to instruct a double return.

What you could do, is set the filename you wish to have downloaded in a session variable, then redirect back to whatever page. Within the redirected page, you could flash your message, along with having an automatic download of the file.

Here is some threads on the topic:

https://stackoverflow.com/questions/25624927/how-do-i-redirect-after-download-in-laravel

https://stackoverflow.com/questions/822707/php-generate-file-for-download-then-redirect/822732#822732

3 likes

Please or to participate in this conversation.