在 Laravel 中,我有一个仅创建但未更新的模型。所以,我只想删除updated_at
场地。但是created_at
字段为必填项。
那么我怎样才能只删除updated_at
场,同时保持created_at
field?
在您的模型中添加以下两行:
public $timestamps = ["created_at"]; //only want to used created_at column
const UPDATED_AT = null; //and updated by default null set
第二种方式:
public $timestamps = false; //by default timestamp true
添加这样的功能:
public function setCreatedAtAttribute($value) {
$this->attributes['created_at'] = \Carbon\Carbon::now();
}
有关 Laravel 时间戳的更多信息see https://laraveldaily.com/8-tricks-with-laravel-timestamps/
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)