如何在不更新 created_at 时间戳的情况下更新模型?
How to update model without updating created_at timestamp?
Laravel 在每个 table(created_at 和 updated_at)上有两个时间戳。
我认为它会在插入新行时插入 created_at 并在更新时更新 updated_at 。然而,当我更新我的模型时,created_at 字段正在更新。
我该如何改变这种行为,或者我应该使用什么方法来更新一行并且只更新 updated_at 时间戳?
现在我使用 $model->save();
$point = Map::find($id);
$point->longitude = $request->longitude;
$point->latitude = $request->latitude;
$point->description = $request->description;
$point->save();
我找到了解决问题的方法。
我手动创建了 created_at 和 updated_at 列,并且 created_at 在更新时分配了 current_timestamp 属性。
Laravel 在每个 table(created_at 和 updated_at)上有两个时间戳。 我认为它会在插入新行时插入 created_at 并在更新时更新 updated_at 。然而,当我更新我的模型时,created_at 字段正在更新。
我该如何改变这种行为,或者我应该使用什么方法来更新一行并且只更新 updated_at 时间戳?
现在我使用 $model->save();
$point = Map::find($id);
$point->longitude = $request->longitude;
$point->latitude = $request->latitude;
$point->description = $request->description;
$point->save();
我找到了解决问题的方法。 我手动创建了 created_at 和 updated_at 列,并且 created_at 在更新时分配了 current_timestamp 属性。