Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

phayes0289's avatar

Using laravel-feed-reader Package to Display News on Laravel Project

I am trying my hand at something new today. I have installed vedmant/laravel-feed-reader and now have a controller providing an array of data to my blade page, as shown below.

I am able to get the basic top-level info to display, but I am stuck on how to get data from another array with the first array, specifically the "thumbnail" data, as shown in the attached screenshot below.

TIA!

==This is my RssFeedController==

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Vedmant\FeedReader\Facades\FeedReader;

class rssfeedcontroller extends Controller
{
    public function index()
    {
        $f = FeedReader::read('https://www.statter911.com/rss');
        $result = [
            'title' => $f->get_title(),
            'description' => $f->get_description(),
            'permalink' => $f->get_permalink(),
            'link' => $f->get_link(),
            'copyright' => $f->get_copyright(),
            'language' => $f->get_language(),
            'image_url' => $f->get_image_url(),
            'author' => $f->get_author()
        ];
        foreach ($f->get_items(0, $f->get_item_quantity()) as $item) {
            $i['title'] = $item->get_title();
            $i['description'] = $item->get_description();
            $i['id'] = $item->get_id();
            $i['content'] = $item->get_content();
            $i['thumbnail'] = $item->get_thumbnail();
            $i['category'] = $item->get_category();
            $i['categories'] = $item->get_categories();
            $i['author'] = $item->get_author();
            $i['authors'] = $item->get_authors();
            $i['contributor'] = $item->get_contributor();
            $i['copyright'] = $item->get_copyright();
            $i['date'] = $item->get_date();
            $i['updated_date'] = $item->get_updated_date();
            $i['local_date'] = $item->get_local_date();
            $i['permalink'] = $item->get_permalink();
            $i['link'] = $item->get_link();
            $i['links'] = $item->get_links();
            $i['enclosure'] = $item->get_enclosure();
            $i['audio_link'] = $item->get_enclosure()->get_link();
            $i['enclosures'] = $item->get_enclosures();
            $i['latitude'] = $item->get_latitude();
            $i['longitude'] = $item->get_longitude();
            $i['source'] = $item->get_source();

            $result['items'][] = $i;
        }
        return view('stater911feed',compact('result'));
    }
}

==My Blade Page==

{{-- RSS Feed Info --}}
<h1>{{ $result['title'] }}</h1>
{{ $result['description'] }}
{{ $result['link'] }}

{{-- RSS News Items in Feed --}}
@foreach ($result['items'] as $item)
<h2>{{ $item['title'] }}</h2>
{!! $item['description'] !!}
{{--INSERT THUMBNAIL IMAGE HERE --}}
@endforeach

==Link to data dump sreenshot==

https://app.screencast.com/hgfP0tfmhx0G1

0 likes
2 replies
LaryAI's avatar
Level 58

To display the thumbnail image in the blade page, you can use an HTML img tag and set the src attribute to the value of the thumbnail key in the $item array. Here's an example:

@foreach ($result['items'] as $item)
    <h2>{{ $item['title'] }}</h2>
    {!! $item['description'] !!}
    @if (isset($item['thumbnail']))
        <img src="{{ $item['thumbnail'] }}" alt="Thumbnail">
    @endif
@endforeach

This code checks if the $item array has a thumbnail key, and if it does, it displays an img tag with the src attribute set to the value of the thumbnail key. If there is no thumbnail key, nothing is displayed.

Note that the isset() function is used to check if the thumbnail key exists in the $item array, to avoid errors if the key is not present.

phayes0289's avatar
phayes0289
OP
Best Answer
Level 5

I converted my RSS feed result to JSON, making it much easier to reference. Was this the best way to do it?

$result = json_decode(json_encode($result));
{!! $item->thumbnail->url !!}

Please or to participate in this conversation.