【发布时间】:2016-01-19 19:25:37
【问题描述】:
我有一个 laravel 项目,它在我的本地版本的 Google 应用引擎上运行良好,但是在部署时 created_at 时间戳正在更改,即使它设置为不更改。
我所有的模型都有
public $timestamps = false;
因为我需要在不影响时间戳的情况下更新行的某些部分,所以我手动执行此操作。
在我的存储库中,我有以下功能:
public function setLock($id)
{
$row = $this->model->find($id);
if(!$row){
return null;
}
$row->timestamps = false;
if($row->locked_at == NULL || strtotime($row->locked_at) < strtotime(date('Y-m-d H:i:s')) || $row->locked_by == Auth::id()){
try{
$row->locked_by = Auth::id();
$row->locked_at = date('Y-m-d H:i:s', strtotime("+5 min"));
$row->save();
return true;
}catch(PDOException $e){
Log::error('Error setting lock at ID:' .$id.': ' . $e->getMessage());
return null;
}
}else{
return false;
}
}
无论是否在模型和函数中设置了时间戳变量,它仍然会更新 created_at 时间戳。
我也试过在模型中设置这个函数:
public function setUpdatedAt($value)
{
//Do-nothing
}
但是,它仍然会更新..
这里有什么我遗漏的吗?
【问题讨论】:
-
您检查过表格中的列吗?这也可能是原因
-
@BinaryGhost created_at 列设置为时间戳,不为空。这是应该的吗?
标签: php laravel laravel-5.1