I am trying to use an array in the WHERE clause with IN () in Laravel, but it's not working as expected. Here’s my current code:
$groupOfTopics = [46, 51, 167, 176, 177, 181, 185, 270, 323, 328, 350];
$Data = DB:: connection('DB')->select(
"Select
....
WHERE code IN (?)", [$groupOfTopics],);
However, this does not return the expected results.
How can I correctly pass an array into the IN clause in Laravel raw queries?
DB::connection('DB')->select(/* ... */)->whereIn('code', $groupOfTopics)?DBfacade... Do you also not use Models and Relationships? I'd be very interested to hear why this choice was made; I can't really think of any good reasons you'd useDB::connection('db')->select(/* entire raw query */)overModel::select(...)->where(...)->get()(and similar).