I want to display a RSS feed, keeping it as simple as possible.
I am using Laravel 4. Here is my controller :
public function getHome()
{
$content = file_get_contents('http://rss.leparisien.fr/leparisien/rss/paris-75.xml');
$flux = new SimpleXmlElement($content);
return View::make('frontend/homepage', compact('flux'));
}
And here is my view :
@foreach ($flux as $flu)
<article class="entry-item">
<img src="{{utf8_decode((string)$flu->item->enclosure['url'])}}" alt="">
<div class="entry-content">
<a href="{{ $flu->item->link }}">{{ $flu->item->title }}</a>
{{ $flu->item->description }}
</div>
</article>
@endforeach
This is working fine, but only one article (item) is shown. I tried to find a way to get several items displayed with SimpleXMLElement::attributes
I can't find any clear tutorial about it.
try this
@foreach ($flux[0]->item->link as $item)
<article class="entry-item">
<img src="{{utf8_decode((string)$item->enclosure['url'])}}" alt="">
<div class="entry-content">
<a href="{{ $item->link }}">{{ $item->title }}</a>
{{ $item->description }}
</div>
</article>
@endforeach
because you have mutliple items