我有一个称为(date)的sql-server列,其类型为int类型,此列的值是时间戳记,如(1538254800),我需要从laravel sql查询中选择此列并将其显示为日期格式(Ymd H:m :i pm)like(2018-09-29 09:00:00 pm)
答案 0 :(得分:0)
https://laravel.com/docs/5.8/eloquent-mutators#attribute-casting
示例:
class MyModel extends Model {
// ...
protected $casts = [
'int_col_name' => 'datetime:u',
];
// ...
}
https://laravel.com/docs/5.8/eloquent-mutators#date-mutators
示例:
class MyModel extends Model {
// ...
protected $dates = [
'int_col_name',
];
// ...
}