Reputation: 2213
I have a route like this:
Route::any("/operations/xml", array("as"=>"operations.xml", "uses"=>"OperationsController@generateXml"));
And my controller generates an xml that saves inside the public folder:
OperationsController.php:
public function generateXml(){
$doc = new DomDocument("1.0", "UTF-8");
$doc->formatOutput = true;
//I add my stuff inside de xml from the database here...
$doc->save("xml/test.xml");
}
But what I need is that when I navigate to the route http://example.com/operations/xml I will be able to download the xml. How can I do this?
Upvotes: 0
Views: 321
Reputation: 11057
Add the following to the end of the function.
return Response::download(public_path() . "xml/test.xml", 'name.xml', array('Content-Type' => 'application/xml'));
The parameters are;
Upvotes: 1