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
107 stars 22 forks source link

Error: Call to a member function contains() on array #39

Closed oaaron99 closed 3 years ago

oaaron99 commented 3 years ago

I'm just starting to get familiar with using your package and so far everything is good except I have run into an error when trying to combine a select with a where on a basic query.

The following query:

Game::select(['name', 'aggregated_rating_count'])->where('aggregated_rating_count', '>', 5)->get();

Results in this error:

Error: Call to a member function contains() on array in file Builder.php on line 259

I don't know if I am doing something wrong but this query seems fine and follows closely to the examples provided in the README.

It seems the source of the error is that when the fields key exists in the $builder->query collection it is returning an array instead of a collection and then calling $select->contains when $select is an array.

Removing the select or even moving it after the where clause results in a working query.

Both of the following result in no errors:

Game::where('aggregated_rating_count', '>', 5)->get();
Game::where('aggregated_rating_count', '>', 5)->select(['name', 'aggregated_rating_count'])->get();

Any insight would be greatly appreciated

marcreichel commented 3 years ago

Hey @oaaron99,

thanks for reporting this.

Indeed there was a little bug so the select method returned an array instead of a collection.

The bug is now fixed with the latest version of the package (v2.4.6) in commit aaaf7da764553f4318688266db0850c5164b25f2.

So feel free to install the latest version to get rid of the bug. Sorry for the inconvenience.