我有以下返回數組的查詢 $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'
嘗試在 PHP Laravel 應用程序中獲取非對象的屬性
慕的地8271018
2023-11-05 15:52:17