response () in XML with Laravel

1

I have studied about the development of APIs with Laravel, a quick question, is it possible to return an XML instead of a json?

instead of doing:

return response()->json($json);

Do something like:

return response()->xml($xml);

I looked for XML in the documentation and did not find it ...

    
asked by anonymous 24.07.2018 / 16:07

2 answers

1

See this extension, it works fine: link

Laravel does not work with xml natively

I hope I have helped!

    
24.07.2018 / 17:44
1

There is nothing specific about XML, but I found this document that talks about file download . But for this you need to download it on the machine before you send it.

return response()->download($pathToFile); 

return response()->download($pathToFile, $name, $headers);

return response()->download($pathToFile)->deleteFileAfterSend(true);

$pathToFile is the directory where you saved your XML. You can use 3 types of parameters.

  • The first one you just pass the file path.

  • The second you path, name and headers

  • The third one you pass the path and specifies whether to delete it after downloading.

24.07.2018 / 17:03