如何让 Laravel Eloquent “IN"询问?

2021-12-26 00:00:00 orm php laravel eloquent

我想在 Laravel Eloquent 中进行查询,就像这里的原始 MySQL 查询

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

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

我在 Laravel Eloquent 中尝试过这个,但它不起作用

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

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

推荐答案

这是你在 Eloquent 中的做法

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();

相关文章