我正在尝试将字符串推入对象中。此错误在以下行引发:
$event->location[0]->image = $mapLocation->image;
在这个函数中:
public static function assignMarkers($events)
{
// Initialise pageIds array and counter
$pageIds = [];
$locations = [];
$locationsCounter = 0;
// Loop events and place unique pages in pageId array
foreach($events as $event)
{
if ( ! in_array($event->location[0]->pageId, $pageIds))
{
array_push($pageIds, $event->location[0]->pageId);
// Construct mapLocation object
$mapLocation = new stdClass();
$mapLocation->latitude = $event->location[0]->latitude;
$mapLocation->longitude = $event->location[0]->longitude;
$mapLocation->pageId = $event->location[0]->pageId;
$mapLocation->image = 'assets/img/markers' . $locationsCounter . '.png';
$locationsCounter++;
array_push($locations, $mapLocation);
// Push image back to event
$event->location[0]->image = $mapLocation->image;
} else {
// it's already in the array
// set the events image to the one in the corresponding location array position
foreach($locations as $location)
{
if ($event->location[0]->pageId == $location->pageId) {
// We have a match
$event->location->image = $location->image;
}
}
}
}
return $events;
}
$ events是一个Eloquent Collection(使用Laravel)。我不确定这个错误意味着什么 - 有人可以帮忙吗?