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

lennartjvw's avatar

IGDB Api in Laravel

Has anyone used the IGDB Api in Laravel? https://github.com/messerli90/igdb

On one page I want to show all PS4 games from the IGDB database. I'm kinda new to Laravel and this is the first time I'm using a API in Laravel.

Route::get('/games', function (){
    $platforms = IGDB::searchPlatforms('playstation');
    return view('games', compact('platforms'));
});
                    @foreach($platforms as $platform)
                        <li>{{ $platform }}</li>
                    @endforeach

I'm still getting this error message: htmlspecialchars() expects parameter 1 to be string, object given.

0 likes
3 replies
Jaytee's avatar

I've never used it but you're receiving that error because the looped $platform is clearly still an object, so echoing it out won't work.

To get a better idea of the API, you can do a dd($platform) to see what properties and methods are available.

EDIT: https://igdb.github.io/api/endpoints/platform/

Read that, this is what is returned when you hit that endpoint. As you can see you get an array of game IDs.

So now you'll need to hit another endpoint for retrieving a game using the ID's you have received back.

By the look of it tho, you can only search for one game at a time. I imagine there will be hundreds of PS4 games, and that's quite an expensive and timely thing to do by sending a request for each game.

You might want to reconsider how you approach this. You could retrieve all games and them store them in a database or cache them, that way you dont hit their API every single time.

lennartjvw's avatar

Ah thx! This helped a lot. From here I can get it work, I think hehe.

36864's avatar

Taking a further look into the API, this might be of use to you:

https://igdb.github.io/api/references/expander/

Still, as @Jaytee pointed out, this is a massive dataset and you should not load it on demand for every request.

Do an initial pull of the data into your database, then periodically check the API for changes and pull only the new data you need.

Please or to participate in this conversation.