问题
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']
]);
回答1:
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
来源:https://stackoverflow.com/questions/61564951/laravel-mutator-doesnt-seem-to-work-on-update