Eloquent选择空字符串或空值的行

时间:2013-12-20 15:26:55

标签: php orm relationship eloquent

我有类似$user->albums()->where('col', NULL)的内容,它运行正常然后我尝试将其扩展为$user->albums()->where('col', NULL)->or_where('col', '')的空字符串,但它无效。

我也看到on this post我可以使用where_null('col'),但它不起作用it's not documented。任何选择空或NULL col

的简单方法

4 个答案:

答案 0 :(得分:26)

尝试使用orWhereNull作为第二个句子:

$users = DB::table('users')
        ->where('col', '=', '')
        ->orWhereNull('col')
        ->get();

答案 1 :(得分:2)

如何?

sale

这样,您可以同时检查两种情况

答案 2 :(得分:0)

试试这个查询:

$users = DB::table('users')
        ->whereRaw('col = "" OR col IS NULL')
        ->get();

答案 3 :(得分:-2)

不确定,但这可能有效:

$user->albums()->where_in('col', array(NULL,''));
相关问题