2016-12-15 38 views
1

我在表中有兩列,分別叫做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

回答

1

檢查你的數據庫表(有這'expired_date'欄),不知道,但問題屬性爲同一列。 如果您發現'expired_date'列的屬性'on update CURRENT_TIMESTAMP',則將其刪除並檢查。

enter image description here

此外而更新動作爲特定記錄(一個或多個)執行此「on update CURRENT_TIMESTAMP」屬性將更新日期與當前上。