在 Laravel 6 应用程序中执行一些操作后,我尝试更新我的模型对象 $last
(CurrentConditions 类)。正如您在下面看到的,我正在尝试将 update_time
属性更新为当前时间戳。除了此属性之外,我在 CurrentConditions 模型中还有另一个时间戳属性:external_update_time
,并且我希望此属性在更新和保存 $last
对象后保持不变。问题是 external_update_time
属性在保存模型后更新为当前时间。
/** @var CurrentConditions $last */
$last = $this->getLastUpdatedCurrentConditions($cityID);
$last->update_time = Carbon::now("UTC");
$last->save();
这是我的模型:
class CurrentConditions extends Model
{
protected $table = 'current_conditions';
...
public $timestamps = false;
protected $dates = ['update_time', 'external_update_time'];
...
}
这是我的迁移代码:
Schema::create("current_conditions", function (Blueprint $table) {
$table->bigIncrements("current_conditions_id");
...
$table->timestamp("external_update_time");
$table->timestamp("update_time")->useCurrent();
});
那么为什么external_update_time
也要更新呢?感谢您的帮助。
最佳答案
请检查更新时是否未设置 external_update_time 以设置 CurrentTimeStamp
在模式表设计中
关于mysql - Laravel 6 - 更新模型时间戳,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59567569/