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

Alphyo's avatar

IGDB API problem with missing index

Hi,

Thanks to the course I followed here on Laracast, I managed to have a decent app up and running :)

I do have a few bugs left, in particular I am still struggling when fetching some old games because the API is missing several keys in those cases.

I did fix a few instances, however I am stuck whenever the game does not have a trailer available. Using both the "isset" and the "array_key_exists" do not seem to work (they do prevent the app from crashing but the trailers are gone from all games.)

To keep it simple, why is the following code, written in the GamesController, working (I mean it both prevent the crash and does not affect games where the key is present:

'involved_companies'=>array_key_exists('involved_companies',$game)?($game['involved_companies'][0]['company']['name']):null,

.... and why does the following code not?

'trailer'=>array_key_exists('trailer',$game)?($game('https://www.youtube.com/embed/'.$game)['videos'][0]['video_id']):null

Thanks!

0 likes
1 reply
Alphyo's avatar

oh well, I fixed it, asking it made me think more carefully :)

'trailer'=>isset($game['videos'])?'https://www.youtube.com/embed/'.$game['videos'][0]['video_id']:null,

so, I was using the wrong key name

Please or to participate in this conversation.