src/ModeResolver/SideloadModeResolver.php
private function addCollectionToRoot(&$root, &$object, $fullPropertyPath)
    {
        // First determine if the $object is a resource or a
        // collection of resources
        $isResource = false;
        if (is_array($object)) {
            $copy = $object;
            $values = array_values($copy);
            $firstPropertyOrResource = array_shift($values);

            if (Utility::isPrimitive($firstPropertyOrResource)) {
                $isResource = true;
            }
        } elseif ($object instanceof EloquentModel) {
            $isResource = true;
        }

        $newCollection = $isResource ? [$object] : $object;

        // Does existing collections use arrays or Collections
        $copy = $root;
        $values = array_values($copy);
        $existingRootCollection = array_shift($values);

        $newCollection = $existingRootCollection instanceof Collection ?
                                new Collection($newCollection) : $newCollection;

        if (!array_key_exists($fullPropertyPath, $root)) {
            $root[$fullPropertyPath] = $newCollection;
        } else {
            $this->mergeRootCollection($root[$fullPropertyPath], $newCollection);
        }
    }
private function addCollectionToRoot(&$root, &$object, $fullPropertyPath)
    {
        // First determine if the $object is a resource or a
        // collection of resources
        $isResource = false;
        if (is_array($object)) {
            $copy = $object;
            $values = array_values($copy);
            $firstPropertyOrResource = array_shift($values);

            if (Utility::isPrimitive($firstPropertyOrResource)) {
                $isResource = true;
            }
        } elseif ($object instanceof EloquentModel) {
            $isResource = true;
        }

        $newCollection = $isResource ? [$object] : $object;

        // Does existing collections use arrays or Collections
        $copy = $root;
        $values = array_values($copy);
        $existingRootCollection = array_shift($values);

        $newCollection = $existingRootCollection instanceof Collection ?
                                new Collection($newCollection) : $newCollection;

        if (!array_key_exists($fullPropertyPath, $root)) {
            $root[$fullPropertyPath] = $newCollection;
        } else {
            $this->mergeRootCollection($root[$fullPropertyPath], $newCollection);
        }
    }
private function addCollectionToRoot ( & $ root , & $ object , $ fullPropertyPath ) { // First determine if the $object is a resource or a // collection of resources $ isResource = false ; if ( is_array ( $ object ) ) { $ copy = $ object ; $ values = array_values ( $ copy ) ; $ firstPropertyOrResource = array_shift ( $ values ) ; if ( Utility :: isPrimitive ( $ firstPropertyOrResource ) ) { $ isResource = true ; } } elseif ( $ object instanceof EloquentModel ) { $ isResource = true ; } $ newCollection = $ isResource ? [ $ object ] : $ object ; // Does existing collections use arrays or Collections $ copy = $ root ; $ values = array_values ( $ copy ) ; $ existingRootCollection = array_shift ( $ values ) ; $ newCollection = $ existingRootCollection instanceof Collection ? new Collection ( $ newCollection ) : $ newCollection ; if ( ! array_key_exists ( $ fullPropertyPath , $ root ) ) { $ root [ $ fullPropertyPath ] = $ newCollection ; } else { $ this -> mergeRootCollection ( $ root [ $ fullPropertyPath ] , $ newCollection ) ; } }
Add the collection to the root array
@param array $root
@param object $object
@param string $fullPropertyPath
@return void
Add the collection to the root array