/** * Sets the given $targetCollection's nested "self" links from the given raw data using the given version number. * * @param Collection|Paginator $rawData Data provided * @param $targetCollection Collection on links are set * @param mixed $version Version number could potentialy come from anywhere */ private function nestedSelfRels($rawData, &$targetCollection, $version) { $nestedData = null; if ($rawData instanceof Model) { $nestedData = $rawData->getRelations(); } else { $nestedData = $rawData; } foreach ($nestedData as $key => $resourceCandidate) { if ($resourceCandidate instanceof ResourceEntity) { // root Resource is a selected Resource not a Collection therefore we need the nested Resource's root rel $addition = $rawData instanceof Model ? $resourceCandidate->getRootRelName() . '/' : ''; $targetCollection[$key]['links'][] = ['self' => Request::url() . '/' . $addition . $resourceCandidate->id]; } if ($resourceCandidate instanceof Collection) { foreach ($resourceCandidate as $rcKey => $innerCandidate) { $targetCollection[$key][$rcKey]['links'][] = ['self' => Request::url() . '/' . $innerCandidate->getRootRelName() . '/' . $innerCandidate->id]; } } } }