Laravel-Mutator似乎在更新上不起作用 [英] Laravel - Mutator doesn't seem to work on update

查看:161
本文介绍了Laravel-Mutator似乎在更新上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下变种器

public function setFormattedCriteriaAttribute($value)
{
    $this->attributes['formatted_criteria'] = serialize($value);
}

当我调用以下代码时,为什么不更新formatted_criteria值-请注意该字段在我的可填充属性数组中列出了?

When I call the following why doesn't it update the formatted_criteria value - note the field is listed in my fillable attributes array ?

$jobAlert = JobAlert::findOrFail($id);

$jobAlert->update([
        'frequency' => $request->frequency,
        'criteria'  => $criteria,
        'formatted_criteria' => ['test']
]);

推荐答案

请确保您的$fillable变量中使用了formated_criteria.

Be sure formated_criteria in your $fillable variable.

更新

如果模型中具有强制转换数组,请修改,否则添加.

if you have casts array in your model modify else add.

protected $casts = [
        'formatted_criteria'    => 'array',
    ];

然后使用二进制文件将您的字段更新为LONGTEXT

then update your field as LONGTEXT with binary

这篇关于Laravel-Mutator似乎在更新上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆