模型中获取器与casts执行顺序
如果同时在casts中定义字段,又定义了字段的获取器,那么获取器中传入的值是casts修改后的还是数据库原始返回的?
class RoomOrderModel extends WorkCommonModel
{
protected $casts = [
"remark" => "array"
];
public function getRemarkAttribute($value): array
{
$data = json_decode($value, true);
if (!is_array($data)) {
$data = [
"text" => $value,
"image" => ""
];
}
return $data;
}
}
方法优先 所以获取器中拿到的是原始值