private function parseItem(Item $item)
    {
        // Get and format an item
        $tmp = $this->getFormattedItem($item);

        // Get related data
        $relationships = $this->getRelationships($item);

        // Closure function to internally parse related includes
        $parseRelationships = function($key, Item $item, array $relationships = []) {
            $related = $this->getFormattedItem($item);

            if (!in_array($related, $this->relationships)) {
                $this->relationships[] = $related;
            }

            unset($related['attributes']);
            unset($related['links']);
            $relationships[$key]['data'][] = $related;

            return $relationships;
        };

        // Loop data to create includes response data
        foreach ($relationships as $key => $value) {
            if ($value instanceof Collection) {
                foreach ($value->getData() as $include_value) {
                    $relationships = $parseRelationships($key, new Item($include_value, $value->getTransformer()), $relationships);
                }
            } else if ($value instanceof Item) {
                $relationships = $parseRelationships($key, $value, $relationships);
            }
        }

        // Pass the relationships data into the item
        $tmp['relationships'] = $relationships;

        // Set the response data
        if (is_array($this->data)) {
            $this->data[] = $tmp;
        } else {
            $this->data = $tmp;
        }

        return $this;
    }
private function parseItem(Item $item)
    {
        // Get and format an item
        $tmp = $this->getFormattedItem($item);

        // Get related data
        $relationships = $this->getRelationships($item);

        // Closure function to internally parse related includes
        $parseRelationships = function($key, Item $item, array $relationships = []) {
            $related = $this->getFormattedItem($item);

            if (!in_array($related, $this->relationships)) {
                $this->relationships[] = $related;
            }

            unset($related['attributes']);
            unset($related['links']);
            $relationships[$key]['data'][] = $related;

            return $relationships;
        };

        // Loop data to create includes response data
        foreach ($relationships as $key => $value) {
            if ($value instanceof Collection) {
                foreach ($value->getData() as $include_value) {
                    $relationships = $parseRelationships($key, new Item($include_value, $value->getTransformer()), $relationships);
                }
            } else if ($value instanceof Item) {
                $relationships = $parseRelationships($key, $value, $relationships);
            }
        }

        // Pass the relationships data into the item
        $tmp['relationships'] = $relationships;

        // Set the response data
        if (is_array($this->data)) {
            $this->data[] = $tmp;
        } else {
            $this->data = $tmp;
        }

        return $this;
    }
private function parseItem ( Item $ item ) { // Get and format an item $ tmp = $ this -> getFormattedItem ( $ item ) ; // Get related data $ relationships = $ this -> getRelationships ( $ item ) ; // Closure function to internally parse related includes $ parseRelationships = function ( $ key , Item $ item , array $ relationships = [ ] ) { $ related = $ this -> getFormattedItem ( $ item ) ; if ( ! in_array ( $ related , $ this -> relationships ) ) { $ this -> relationships [ ] = $ related ; } unset ( $ related [ 'attributes' ] ) ; unset ( $ related [ 'links' ] ) ; $ relationships [ $ key ] [ 'data' ] [ ] = $ related ; return $ relationships ; } ; // Loop data to create includes response data foreach ( $ relationships as $ key => $ value ) { if ( $ value instanceof Collection ) { foreach ( $ value -> getData ( ) as $ include_value ) { $ relationships = $ parseRelationships ( $ key , new Item ( $ include_value , $ value -> getTransformer ( ) ) , $ relationships ) ; } } else if ( $ value instanceof Item ) { $ relationships = $ parseRelationships ( $ key , $ value , $ relationships ) ; } } // Pass the relationships data into the item $ tmp [ 'relationships' ] = $ relationships ; // Set the response data if ( is_array ( $ this -> data ) ) { $ this -> data [ ] = $ tmp ; } else { $ this -> data = $ tmp ; } return $ this ; }
Parses an item into response data

@param Item $item Resource item
@return $this Instance of self
Parses an item into response data