是否有任何理由雄辩$casts
无法正常工作?
我正在存储json,json列类型和
protected $casts = [
'fields' => 'array'
];
但是...
\App\Lead::find(1)->fields
仍然返回json
"{"first_name":"Brian","last_name":"Dillingham","email":"brian@gmail.com"}"
我变异时甚至不起作用
public function getFieldsAttribute($value)
{
return json_decode($value, true);
}
但是当我
时有效dd(json_decode(\App\Lead::find(1)->fields, true));
答案 0 :(得分:1)
只需从mutator函数中输入:
public function getFieldsAttribute($value)
{
return (array) json_decode($value, true);
}