How to get XML response output in laravel?

How to get XML response output in laravel? or
How to create XML response output in laravel? or
Most of developers use header function to create xml file but this does not work
header('Content-type: application/xml');
$output  = "<?xml version='1.0' encoding='UTF-8'?>";

here i will tell you that how can you show or save XML response output in laravel
you have an array where you have data

Here is an example that how can you create xml file response in laravel
suppose you have an array which have twitter data

//Preapre our output for xml data
$output  = "<?xml version='1.0' encoding='UTF-8'?>";
$output .= "\n<twitterfeed>\n";
$j=0;
foreach($twitterinfo as $row){
$j++;
$output .= "<feed>\n";
$output .= "<id>" . $j . "</id>\n";
$output .= "<twitter_id>" . $row['twitter_id'] . "</twitter_id>\n";
$output .= "<isactive>" . $row['isactive'] . "</isactive>\n";
$output .= "<twitter_name>" . str_replace('&', '&amp;', $row['twitter_name']) . "</twitter_name>\n";
$output .= "</feed>\n";
}
$output .= "</twitterfeed>";
return Response::make($output, 200)->header('Content-Type', 'application/xml');

Comments