我在模型中有:
protected $casts = [
'date' => 'date',
];
Laravel有没有设置类型转换格式的能力,例如:
protected $casts = [
'date' => 'date_format:d/m/yyyy',
];
?
已编辑
我尝试了这个:
在模型中:
protected $dateFormat = 'm/d/Y';
protected $dates = ['driver_expiration', 'created_at', 'updated_at', 'deleted_at'];
protected $casts = [
'driver_expiration' => 'date',
];
我将日期(driver_expiration)保存为'01/012016',但实际上保存的是0000-00-00。
Laravel文档: https://laravel.com/docs/5.1/eloquent-mutators 告诉我们$dateFormat仅适用于时间戳('created_at','updated_at','deleted_at')。
protected $dates
Carbon 类型声明中使用强制类型转换? - Yevgeniy Afanasyev