I have Email model with:
public function getEmailJsonAttribute($value)
{
return $value ? json_decode($value) : $value;
}
public function setEmailJsonAttribute($value)
{
return $value ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
}
and have code in controller
$email = new Email([
'email_json' => ['a' => 1, 'b' => 2],
]);
dd($email->email_json);
i expect see some json string but saw NULL why?
I think your mutator needs to look like this
public function setEmailJsonAttribute($value)
{
$this->attributes['email_json'] = json_encode($value, JSON_UNESCAPED_UNICODE);
}
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community