选择其"date_field< NOW()` [英] Selecting entries whose `date_field < NOW()`
本文介绍了选择其"date_field< NOW()`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我尝试运行以下查询时,它不返回任何内容:
When I try to run the following query, it returns nothing:
Item::where(\DB::raw('date_field < NOW()'))->get()
这样做的原因是,将is null
附加到生成的MySQL查询中,如下所示:
The reason for this is, that is null
is appended to the generated MySQL query like this:
SELECT * FROM items WHERE date_field < NOW() is null;
为什么is null
部分被附加到上面的查询中?
Why does the is null
part get appended to the above query?
推荐答案
This is a known issue in Laravel and has been reported on their GitHub page. Use whereRaw()
instead and pass a string:
Item::whereRaw('date_field < NOW()')->get()
这篇关于选择其"date_field< NOW()`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文