laravel5.2 使用update更新数据,为什么created_at也被更新了?
程序员文章站
2022-05-28 10:14:01
...
执行函数
public function registerStore(Requests\RegisterRequest $request){
$user=User::user();
$res=$user->update($request->all());
return redirect('/');
}
User.php
protected $fillable = [
'name', 'email', 'password', 'openid','user_id','truename','tel','card','bank_name','bank_branch'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
就是很普通的更新,user数据已经有了的。
6.24更新,我讲user表中crated_at字段的extra值设为null,似乎就好了,之前是on update CURRENT_TIMESTAMP
回复内容:
执行函数
public function registerStore(Requests\RegisterRequest $request){
$user=User::user();
$res=$user->update($request->all());
return redirect('/');
}
User.php
protected $fillable = [
'name', 'email', 'password', 'openid','user_id','truename','tel','card','bank_name','bank_branch'
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
就是很普通的更新,user数据已经有了的。
6.24更新,我讲user表中crated_at字段的extra值设为null,似乎就好了,之前是on update CURRENT_TIMESTAMP
似乎有其他人碰到這種問題:https://github.com/laravel/framework/issues/11518
試試看建立 migration
時
$table->timestamp('created_at')->useCurrent();
$table->timestamp('updated_at')->useCurrent();
或是
$table->nullableTimestamps();
上一篇: AngularJS注册表单验证的步奏详解
下一篇: php中foreach循环问题