0

Laravel Model 设置 casts 转换类型,部分字段没有生效

jeo created at5 years ago view count: 3152

Laravel Model 设置 casts 转换类型没有生效, deleted_at 不生效。balance是OK的。

class User extends Model
{
    protected $table = 'users';
    public $timestamps = true;
    protected $guarded = [];
    protected $casts = [
        'deleted_at' => 'string',
        'balance' => 'double',
    ];
report
回复
0

deleted_at 可能是Laravel内部自带的属性,所以没有生效。 试了下下面的方式转换成功了。

// 在Laravel Model 里面添加
    public function getDeletedAtAttribute()
    {
        return (string)$this->attributes['deleted_at'];
    }
5 years ago 回复

Recent search keywords