【发布时间】:2017-03-10 09:02:39
【问题描述】:
如果我想在我的模型上使用这个特性,在哪里制作文件
如果我想在里面有这个特征,这个文件应该是什么样子:
trait FormatDates
{
protected $newDateFormat = 'd.m.Y H:i';
// save the date in UTC format in DB table
public function setCreatedAtAttribute($date){
$this->attributes['created_at'] = Carbon::parse($date);
}
// convert the UTC format to my format
public function getCreatedAtAttribute($date){
return Carbon::parse($date)->format($this->newDateFormat);
}
// save the date in UTC format in DB table
public function setUpdatedAtAttribute($date){
$this->attributes['updated_at'] = Carbon::parse($date);
}
// convert the UTC format to my format
public function getUpdatedAtAttribute($date){
return Carbon::parse($date)->format($this->newDateFormat);
}
// save the date in UTC format in DB table
public function setDeletedAtAttribute($date){
$this->attributes['deleted_at'] = Carbon::parse($date);
}
// convert the UTC format to my format
public function getDeletedAtAttribute($date){
return Carbon::parse($date)->format($this->newDateFormat);
}
}
以及如何在用户模型类上应用它...
【问题讨论】:
标签: laravel-5.3