Laravel/雄辩的whereIn与null [英] Laravel / Eloquent whereIn with null

查看:57
本文介绍了Laravel/雄辩的whereIn与null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何应用Laravel的Eloquent whereIn()使其包含null?

How do I apply Laravel's Eloquent whereIn() so that it includes null?

我尝试过:

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

还有

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

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

But both queries return no results.

谢谢!

推荐答案

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

I don't think you can pass null in in mysql statement. If you run the query in mysql console it will skip the null.

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

这篇关于Laravel/雄辩的whereIn与null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆