Laravel whereDate 和 where
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47407556/
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
Laravel whereDate and where
提问by Chandimal Harischandra
I'm using laravel 5.4, and I need to check both event and created date conditions at once. So I used following code,
我正在使用 laravel 5.4,我需要同时检查事件和创建日期条件。所以我使用了以下代码,
protected $table = 'qlog';
public $timestamps = false;
public function getAbondonedCalls(){
$results = DB::table('qlog')
->whereDate('created', '=', DB::raw('curdate()'))
->where('event', '=', 'ABANDON')
->get();
var_dump($results);
die();
}
But this code returns nothing. After removing this line it returns a record.
但是这段代码什么都不返回。删除此行后,它会返回一条记录。
->whereDate('created', '=', DB::raw('curdate()'))
How to add both conditions?
如何添加这两个条件?
回答by AddWeb Solution Pvt Ltd
You should try this:
你应该试试这个:
->whereDate('created', '=', date('Y-m-d'))
回答by Chata
For convenience, if you want to verify that a column is equal to a given value, you may pass the value directly as the second argument to the whereDate method: i.e. without including '=' sign
为方便起见,如果要验证列是否等于给定值,可以将该值直接作为第二个参数传递给 whereDate 方法:即不包含 '=' 符号
->whereDate('created', date('Y-m-d'))

