在 resource 中使用 array_get () 调用 $this 的关联关系获取字段时返回为空 有什么好的办法么?
如下代码获取关联关系字段时 'brand1' 'brand2' 使用上边的可以获取到 使用下边的array_get 取不到值
???
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'brand1' => $this->series->brand->name ,
'brand2' => array_get($this,'series.brand.name') ,
];
}
推荐文章: