Action button that can download file.

I created an action button that uses an action class which returns a response()->download() that should download a file when clicked. It returns a successful notification but the download wont start.
No description
No description
16 Replies
charlie
charlie2w ago
The download instruction looks fine, is the $zipFilePath correct?
Karl Marx
Karl MarxOP2w ago
yes. if I use a controller for the action class it works
Dennis Koch
Dennis Koch7d ago
You don't return anything from your action.
Karl Marx
Karl MarxOP7d ago
Dont return anything from the action button?
Dennis Koch
Dennis Koch7d ago
The action closure returns void. You should return the response you are creating in.
Karl Marx
Karl MarxOP7d ago
Thanks @Dennis Koch
Solution
Karl Marx
Karl Marx7d ago
No description
Dennis Koch
Dennis Koch7d ago
BTW I don’t think the isSucessful makes sense. It probably just checks the return code of the response which should always be 200
Karl Marx
Karl MarxOP7d ago
Just returning the response better?
Dennis Koch
Dennis Koch7d ago
Does response()->download() send a 404 when the file is not there? Or does it throw an exception?
Karl Marx
Karl MarxOP6d ago
It throws an exception,
Takashi
Takashi6d ago
you can check something to fix it 1. ensure correct response type 2. Action class Structure
public function handle() { $filePath = storage_path('app/public/file_to_download.pdf'); if (file_exists($filePath)) { return response()->download($filePath); } return back()->with('error', 'File not found.'); }
3. check for Redirects or Response Modifications
Dennis Koch
Dennis Koch6d ago
Then a try catch would be better than your current if
Karl Marx
Karl MarxOP6d ago
No description
Karl Marx
Karl MarxOP6d ago
Like this?
Dennis Koch
Dennis Koch5d ago
Success probably doesn’t make sense. In case of error it sends both then. Otherwise yes
Want results from more Discord servers?
Add your server