问答 / 6 / 2 / 创建于 7年前
想问一下各位大神,laravel怎样在查询数据的时候把时间格式化,谢谢
在 Model 文件中添加 $casts 变量
https://learnku.com/docs/laravel/5.5/eloquent-muta...
在model里面添加属性对应的方法
public function setStartTimeAttribute($value) { $this->attributes['start_time'] = is_int($value) ? $value : strtotime($value); } public function getStartTimeAttribute() { return date('Y-m-d H:i:s', $this->attributes['start_time']); }
我要举报该,理由是:
推荐文章: