I was having problem getting Chrome to recognize a page as RSS or XML feed. Although Firefox has no problem recognizing it, I’m quite sure I’m missing something here.
After some searches, it became clear that the page was returned as a text document. So Chrome simply display the page as HTML. Firefox is smart enough to check the content first before deciding what type of document it is.
In normal PHP circumstances, we would insert header(‘Content-Type’,’text/xml’) before displaying the view. But with Laravel’s blade, that doesn’t work.
The solution was written in Laravel’s documentation, though not obvious.
To return a page as XML, use
return Response::make($content, '200')->header('Content-Type', 'text/xml');
But how to return a view with the header?
Just set the $content to your view. Full code like this:
$content = View::make('home')->with('somevar', $somevar); return Response::make($content, '200')->header('Content-Type', 'text/xml');