Dymantic / laravel-instagram-feed

147 stars 51 forks source link

Cannot use object of type Dymantic \ InstagramFeed \ InstagramMedia as array #45

Closed xDesignX closed 2 years ago

xDesignX commented 2 years ago

Hello,

Thank you in advance for your assistance, Thanks for your plugin

I have a problem when I want to display the Instagram feed I added the profile, the token, everything, and authorize but when displaying the foreach I get the following error

Cannot use object of type Dymantic \ InstagramFeed \ InstagramMedia as array

my sight : $feed = \Dymantic\InstagramFeed\Profile::where('username', 'myaccount')->first()->feed($limit = 10);

my controller: return view('frontend.index', compact('categories'))->with(['instagram' => $feed]);

thank you for your help

michaeljoyner commented 2 years ago

Hi @xDesignX I assume you are using version 3, and there have been some changes from version 2. The feed items are no longer arrays, they are instances of InstagramMedia. You can either update your views to use the object syntax, such as $item->url or you can convert the feed to arrays ($feed->collect()->map->toArray()) and your view should be fine. You can see more in the upgrade guide or in this section of the readme.