get()-6ren">
gpt4 book ai didi

eloquent - Laravel/Eloquent whereIn 为 null

转载 作者:行者123 更新时间:2023-12-03 06:40:43 29 4
gpt4 key购买 nike

如何应用 Laravel 的 Eloquent whereIn() 以便它包含 null?

我已经尝试过:

User::whereIn("column", [null, 1, 2]) -> get();

还有

User::whereIn("column", [DB::raw("null"), 1, 2]) -> get();

但是两个查询都没有返回结果。

谢谢!

最佳答案

我认为你不能在 in mysql 语句中传递 null 。如果您在 mysql 控制台中运行查询,它将跳过 null。

尝试 User::whereNull('column')->orWhereIn('column', array(1, 2))->get();

关于eloquent - Laravel/Eloquent whereIn 为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40657940/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com