简体   繁体   中英

Laravel - Mutator doesn't seem to work on update

I have the following mutator:

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

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']
]);

Be sure formated_criteria in your $fillable variable.

Update

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

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

then update your field as LONGTEXT with binary

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM