Adding RSS to Your Site
Using this library https://packagist.org/packages/thujohn/rss
We simply install but using a forked version so it works with L5
"require": {
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"thujohn/rss": "dev-master"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/majortom731/rss-l4.git"
}
],
composer update
And as they note in the docs
'providers' => array(
'Thujohn\Rss\RssServiceProvider',
)
Now in my route I simply put
Route::get('feed', function() {
$feed = Thujohn\Rss\RssFacade::feed('2.0', 'UTF-8');
$feed->channel(array('title' => 'Incomings.io Blog and News', 'description' => 'Latest News and Blog postings for Incomings.io', 'link' => 'http://incomings.io/feed'));
$blogs = Blog::all();
foreach ($blogs as $blog){
$feed->item(array('title' => $blog->title, 'description|cdata' => $blog->body, 'link' => 'http://incomings.io/blogs/' . $blog->id));
}
return Response::make($feed, 200, array('Content-Type' => 'text/xml'));
});
And nothing fancy here I just output my blog model. I could limit to the latest 10 or output the data better but for now.
comments powered by Disqus