Search code examples
rsslaravel-5.1

Make an rss feed with Laravel 5.1


I make application with Laravel 5.1 only I need to get some posts as XML in an RSS feed.

I am using Laravel 5.1. I found a lot of solutions for Laravel 4 which don't work for 5.1.

I tried this code, but how can I path my data to view?

return response('rss', 200,['Content-Type'=> "application/xml"]);

and this

return response($posts, 200,['Content-Type'=> "application/xml"]);

but this code returns only json data.


Solution

  • i did it thanks every one this is my code

        $xml = new \XMLWriter();
        $xml->openMemory();
        $xml->startDocument();
        $xml->startElement('users');
        foreach($users as $user) {
            $xml->startElement('data');
            $xml->writeAttribute('id', $user->id);
            $xml->writeAttribute('firstname', $user->firstname);
            $xml->writeAttribute('lastname', $user->lastname);
            $xml->writeAttribute('email', $user->user->name);
            $xml->endElement();
        }
        $xml->endElement();
        $xml->endDocument();
    
        $content = $xml->outputMemory();
        $xml = null;
    
        return response($content)->header('Content-Type', 'text/xml');
    

    Answer Url

    How can i store data from mysql to XML in Laravel 5?