Skip to content
Advertisement

Laravel 4 where in condition with DB::select query

I have next SQL query:

JavaScript

How should I execute this using Laravel? I put this query in DB::select function, but how can I place all ids in “WHERE device_id IN (?)” condition? I tried using “array(implode(‘,’, $var))” but it doesnt work. If I have ids like “13, 14” I get results only for id = 13.

So the question is how to place instead of “?” array of ids?

Advertisement

Answer

Laravel is using PDO library. Sadly, binding with PDO doesn’t work with WHERE IN. You can read about it here.

So what you have to do is to put prepared string in your query like this:

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement