單獨在模型里面設置:(推薦)
protected $autoWriteTimestamp = true; // int 型 protected $autoWriteTimestamp = 'datetime'; // datetime 類型 protected $autoWriteTimestamp = false; // 關閉自動寫入時間戳 protected $updateTime = false; // 只關閉自動寫入update_time字段
在config中添加全局設置:
// 開啟自動寫入時間戳字段(官方手冊這么說,自己並沒有測試出來)
'auto_timestamp' => true, // 默認為int型
'auto_timestamp' => 'datetime', // datetime類
'auto_timestamp' => false,
// 關閉全局自動寫入時間字段
如果數據表字段不是默認值(假設數據庫字段名為create_at和update_at)
// 定義時間戳字段名 protected $createTime = 'create_at'; // 默認的字段為create_time 和 update_time protected $updateTime = 'update_at';