I'm trying to generate a XML file using Laravel. Starting from the Controller, where I generate the data that I need to use on the XML file. I generate the XML file using a blade template but I can't save the file or download it automatically
$xml_datos = [];
$total = 0;
.
.
.
$output = View::make('site.contabilidad.adeudosXML')->with(compact(('xml_datos', 'total'))->render();
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\">" .$output;
return $xml;
I need the file to be downloaded, not showed. I've tried using the class Storage and Filesystem but none of them seems to work
You could create a Response like this:
public function saveXML()
{
$output = View::make('site.contabilidad.adeudosXML')->with(compact(('xml_datos', 'total'))->render();
$xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>
<Document xmlns=\"urn:iso:std:iso:20022:tech:xsd:pain.008.001.02\">" .$output;
$response = Response::create($xml, 200);
$response->header('Content-Type', 'text/xml');
$response->header('Cache-Control', 'public');
$response->header('Content-Description', 'File Transfer');
$response->header('Content-Disposition', 'attachment; filename=' . yourFileNameHere . '');
$response->header('Content-Transfer-Encoding', 'binary');
return $response;
}
Also, i strongly recommend you using the PHP functions to manipulate XML.