如何使Laravel雄辩“IN”查询?

时间:2022-10-25 07:48:07

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

我想在Laravel Eloquent中查询它的原始MySQL查询

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

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

我在Laravel Eloquent尝试了这个,但它没有用

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

2 个解决方案

#1


124  

Here is how you do in Eloquent

以下是您在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();

#2


6  

If you are using Query builder then you may use a blow

如果您使用的是“查询”构建器,那么您可能会受到打击

DB::table(Newsletter Subscription)
->select('*')
->whereIn('id', $send_users_list)
->get()

If you are working with Eloquent then you can use as below

如果您正在使用Eloquent,那么您可以使用如下

$sendUsersList = Newsletter Subscription:: select ('*')
                ->whereIn('id', $send_users_list)
                ->get();

#1


124  

Here is how you do in Eloquent

以下是您在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();

#2


6  

If you are using Query builder then you may use a blow

如果您使用的是“查询”构建器,那么您可能会受到打击

DB::table(Newsletter Subscription)
->select('*')
->whereIn('id', $send_users_list)
->get()

If you are working with Eloquent then you can use as below

如果您正在使用Eloquent,那么您可以使用如下

$sendUsersList = Newsletter Subscription:: select ('*')
                ->whereIn('id', $send_users_list)
                ->get();