我有以下返回数组的查询
$wines = Wine::all();
//Remove type_id and producer_id
foreach ($wines as $wine) {
$location = $wine->producer->location;
}
如果我 echo $wine-> Producer-> location; 这就是我得到的结果;
{"city": "Kavadartsi", "address": "29-ти Ноември, бр. 5, Kavadartsi 1430", "country": "Macedonia"}
所以我需要的唯一属性是我尝试访问的地址
$wine->producer->location->address;
但是当我这样做时,我收到以下错误
Trying to get property 'address' of non-object
如果我将代码更改为
$wine->producer->location['address'];
错误是:
Illegal string offset 'address'
白板的微信
慕标5832272