php Eloquent 选择带有空字符串或空值的行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20706874/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Eloquent select rows with empty string or null value
提问by Jonathan de M.
I have something like $user->albums()->where('col', NULL), it works fine then I tried to extend it to empty strings with $user->albums()->where('col', NULL)->or_where('col', '')and it's not working.
我有类似的东西$user->albums()->where('col', NULL),它工作正常,然后我尝试将其扩展为空字符串,$user->albums()->where('col', NULL)->or_where('col', '')但它不起作用。
Also I saw on this postthat I could use where_null('col')but it's not working and it's not documented. Any simple method to select where empty or NULL col
另外我在这篇文章中看到我可以使用where_null('col')但它不起作用并且没有记录。任何简单的方法来选择空或NULL col
回答by Jon
Try using orWhereNullfor the second clause:
尝试orWhereNull用于第二个子句:
$users = DB::table('users')
->where('col', '=', '')
->orWhereNull('col')
->get();
回答by Sim0n222
Not sure, but this might work:
不确定,但这可能有效:
$user->albums()->where_in('col', array(NULL,''));

