Php – How to set the filename for a downloadable file in laravel

laravellaravel-5php

Hi i want to rename the a file that can be downloaded from the website.

This is how i populate the response.

return response()->view('ordersxml.order-template',compact('order','debtor','today'))->header('Content-Type','text/xml')->header('Content-disposition','attachment')->header('filename','test');

The ->header('filename','test');

Is not working.
What am i doing wrong?

THanks in advance

Best Solution

Of course, you can add header filename, but it won't work, because proper header for download is:

Content-Disposition: attachment; filename="filename.jpg"

So, you code should be:

return response()
     ->view('ordersxml.order-template',compact('order','debtor','today'))
     ->header('Content-Type','text/xml')
     ->header('Content-disposition','attachment; filename="test"'));