How to Make Laravel Eloquent "IN" Query?

Ravi Jethva picture Ravi Jethva · Mar 18, 2015 · Viewed 164.1k times · Source

I want to make query in Laravel Eloquent like here its raw MySQL query

SELECT  * from  exampleTbl where id in(1,2,3,4)

I have tried this in Laravel Eloquent but it's not working

DB::where("id IN(23,25)")->get()

Answer

Raheel picture Raheel · Mar 18, 2015

Here is how you do in Eloquent

$users = User::whereIn('id', array(1, 2, 3))->get();

And if you are using Query builder then :

$users = DB::table('users')->whereIn('id', array(1, 2, 3))->get();