I have a problem with exporting kml and gpx files using laravel controller: for json export I use function
public function mapExportJSON(Request $request) {
$client = new Client();
$http = $client->post(
'https://myurl' ,
[
'body' => json_encode(array('points' => $request->points)),
'headers' => [
'Cache-Control' => 'no-cache',
'Content-type' => 'application/json',
]
]
);
$result = $http->getBody()->getContents();
return response($result)
->header('Content-Disposition', 'attachment; filename=route.json');
}
I use formatter for xml, but it doesn't work :(
public function mapExportKML(Request $request) {
$client = new Client();
$http = $client->post(
'https://myurl' ,
[
'body' => json_encode(array('points' => $request->points)),
'headers' => [
'Cache-Control' => 'no-cache',
'Content-type' => 'application/json',
]
]
);
$result = $http->getBody();
$formatter = Formatter::make($result, Formatter::JSON);
$xml = $formatter->toXml();
return response($xml)
->header('Content-Disposition', 'attachment; filename=route.kml')
->header('Content-Type', 'application/xml');
}
Сan anyone help me?