【发布时间】:2017-11-17 20:49:52
【问题描述】:
我想通过在 eloquent 中比较日期来检查促销代码的有效性,但不知道为什么它不起作用
$promoCode = self::where('code', $code)
->where('start_date', '>=', Carbon::now()->toDateString())
->where('end_date', '<=', Carbon::now()->toDateString())
->first();
如果我注释掉第 2 行和第 3 行,那么它工作正常。 MySQL 列类型是 date。我也尝试了 whereDate 方法,但那也不起作用
【问题讨论】: