I’m trying to retrieve some data from my MySQL database, but It’s not working using Eloquent (I’m getting 0 rows). I’s a very simple query, but is driving me crazy.
This is the query in PHP:
$slideshowIdList = Media_slideshow::select('idSlideshow')
->whereIn('idMedia',$idList)
->groupBy('idSlideshow')
->get()
->toArray();
Laravel’s query log shows that the query I wanted to do is okay:
Array
(
[0] => Array
(
[query] => select `idSlideshow` from `media_slideshow` where `idMedia` in (?) group by `idSlideshow`
[bindings] => Array
(
[0] => 11
)
[time] => 0.49
)
)
And this it the same query showing the results in Phpmyadmin:
The Media_slideshow model:
class Media_slideshow extends Model
{
private $idMedia;
private $idSlideshow;
protected $table = "media_slideshow";
}
Am I missing something?
UPDATE:
Hardcoding the second parameter in ->whereIn()
works. Any clue?
->whereIn('idMedia',[11])
2
Answers
Try this:
The format of your
$idList
array is wrong. Try to print it as suggested. Refer to my comment above.