Can you show the result of
dd($game);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi guys,
I'm working along with the Video Game Aggregator series, and feel I've got a good understanding of how most things work as there were various fixes that needed to be done since the series is a bit outdated now. However I keep getting errors when I try to access anything on an offset array. I've been pushing these fixes back as I've not been able to find anything solid online in regards to fixing the issue, apart from I think it would've worked in PHP 7.4 but only as it was more forgiving with errors.
private function formatGameForView($game) /* Removes the formatting logic from View. Check item is in array, then append or pluck specific keys */
{
return collect($game)->merge([
'coverImageUrl' => array_key_exists('cover', $game) ? Str::replaceFirst('thumb', 'cover_big', $game['cover']['url']) : 'No picture',
'social' => [
'instagram' => collect($game['websites'])->filter(fn ($website) => Str::contains($website['url'], 'instagram'))->first(),
'twitter' => collect($game['websites'])->filter(fn ($website) => Str::contains($website['url'], 'twitter'))->first(),
'facebook' => collect($game['websites'])->filter(fn ($website) => Str::contains($website['url'], 'facebook'))->first(),
], /* Cannot access offset array of type string on string */
'involvedCompanies' => $game['involved_companies'][0]['company']['name'], /* Array access offset on int value error
]);
}
This is the method I've got which formats my data, the social details come through the 'websites' endpoint from the IGDB API and I'm trying to access only Instagram, Facebook and Twitter and save them in to the 'Social' array. From what I've read its a problem when putting array elements in to a string but I'm confused because the 'Str::contains' is what looks for the website name as the 'website' end point comes with no specific name just the URL & ID.
<a href="{{$game['social']['instagram']['url']}}" class="hover:text-gray-400"> </a> */how I am trying to link the url*/
This is how I'm trying to access the url for the social networks. When I dump the game collection there is a 'Social' array key that lists all the details I am requesting it's just displaying them that gives me the error. Any ideas on why?
I also get a similar problem with the involved companies however I get the error "Trying to access array offset on value of type int" so I'm confused on two separate offset arrays.
Any help or even pointers in the right direction are massively appreciated!! Thank you
Please or to participate in this conversation.