【发布时间】:2014-02-12 10:14:38
【问题描述】:
你如何用 Eloquent 检查一个字段是否不为空?
我尝试了Model::where('sent_at', 'IS NOT', DB::raw('null'))->...,但它提供了IS NOT 作为绑定而不是比较。
DB::getQueryLog() 是这么说的:
'query' => string 'select * from my_table where sent_at = ? and profile_id in (?, ?) order by created_at desc' (length=101)
'bindings' =>
array (size=3)
0 => string 'IS NOT' (length=6)
1 => int 1
2 => int 4
【问题讨论】:
-
你可以尝试使用
!=而不是IS NOT。 -
@JaTochNietDan != 运算符不适用于 NULL 值。根据MySQL Documentation:“您不能使用算术比较运算符,例如 =、 来测试 NULL。”