【发布时间】:2017-12-19 19:28:41
【问题描述】:
下面是我的数组结果。我正在尝试访问子区域数据,但我一直运行到一个错误:
不能使用类型的对象作为数组
我用过$result[$some_imdex]->subLocality,但没用。
array:5 [▼
0 => GoogleAddress {#204 ▼
-id: "ChIJGzuDx6X1OxARcJhhmLrPLPs"
-locationType: "ROOFTOP"
-resultType: array:1 [▶]
-formattedAddress: "27b Bolaji Street, Maroko, Lagos, Nigeria"
-streetAddress: null
-intersection: null
-political: "Nigeria"
-colloquialArea: null
-ward: null
-neighborhood: "Maroko"
-premise: null
-subpremise: null
-naturalFeature: null
-airport: null
-park: null
-pointOfInterest: null
-establishment: null
-subLocalityLevels: AdminLevelCollection {#205 ▶}
-coordinates: Coordinates {#207 ▶}
-bounds: Bounds {#208 ▶}
-streetNumber: "27b"
-streetName: "Adewale Kolawole Crescent"
-subLocality: "Eti-Osa"
-locality: "Lagos"
-postalCode: null
-adminLevels: AdminLevelCollection {#209 ▶}
-country: Country {#212 ▶}
-timezone: null
-providedBy: "google_maps"
}
1 => GoogleAddress {#213 ▶}
2 => GoogleAddress {#221 ▶}
3 => GoogleAddress {#228 ▶}
4 => GoogleAddress {#236 ▶}
]
【问题讨论】:
-
你可以用collect($array)把一个数组变成一个集合,你试过吗?
-
谢谢。不,我现在就试试看它是否有效
-
我将其转为收藏,但我仍然无法访问“subLocality”数据
-
你得到这个错误的索引是什么?真的是 0..4 吗?
-
哦,已经是收藏了。很简单,你必须在上面使用收集方法。 $result->where('id', $some_id)->first()->property_you_want