laravel雄辩查询生成器更新自定义时间戳字段没有任何逻辑

问题描述:

我在表中有两列,分别叫做expired(boolean)expire_date(timestamp)。我运行一个调度程序来检查优惠券是否已过期everyMinute(),同时使用foreach更新expired列值,我发现它使用今天的日期更改expired_date列值。我发现这个奇怪的或可我参照的东西在这里搞乱与通..是代码laravel雄辩查询生成器更新自定义时间戳字段没有任何逻辑

$schedule->call(function() { 
      CoursePromotion::where('expired',0) 
       ->whereDate('expire_date','<',Carbon::today()) 
       ->update(['expired' => 1]); 
     })->everyMinute(); 

这里是结果,

DB更新

enter image description here

DB运行后php artisan schedule:run命令

enter image description here

谁能告诉我为什么expired_date已经更新为今天的日期?

+0

使用'Carbon :: now()',而不是'Carbon :: today()',第二个只返回日期而不是实际时间 – Vuldo

检查你的数据库表(有这'expired_date'栏),不知道,但问题属性为同一列。 如果您发现'expired_date'列的属性'on update CURRENT_TIMESTAMP',则将其删除并检查。

enter image description here

此外而更新动作为特定记录(一个或多个)执行此“on update CURRENT_TIMESTAMP”属性将更新日期与当前上。