marcreichel / igdb-laravel

Simplify the integration of the IGDB API into your Laravel app. Including IGDB webhook support.
https://marcreichel.dev/docs/igdb-laravel
MIT License
104 stars 22 forks source link

Some Company::find() requests null? #37

Closed PiousVenom closed 3 years ago

PiousVenom commented 3 years ago

I'm trying to run the following: $company = Company::find(95000);. I got the 95000 from a game query in the involved_companies. Are some company returns really null?

marcreichel commented 3 years ago

null is returned whenever a result could not be found. In your case the company could not be found because the 95000 refers to an InvolvedCompany which is different to a normal Company. The InvolvedCompany has a company which holds the regular Company you are looking for (14486 in your case).

You can simplify your API call by expending your request like so:

$game = Game::with(['involved_companies', 'involved_companies.company'])->find(1905); // Fortnite in this example
dd($game->involved_companies->first()->company->name); // returns "People Can Fly"

This way you have only one API call and do not need to query the API again with the ID of the InvolvedCompany and then query the API again with the ID of the Company you got from the previous API call.

PiousVenom commented 3 years ago

That... makes some sense. Looking at the return attributes of involved_companies, I thought that was the company itself. Thanks for the help.

marcreichel commented 3 years ago

Glad to help 😊