protected function getRelatedTransformation($item, $relation)
    {
        // get nested relations separated by the dot notation.
        // we only get one relation at a time because recursion handles the remaining relations.
        $nestedRelations = explode('.', $relation, 2);
        $relation = $nestedRelations[0];

        $result = $item->{$relation};
        $related = $result;

        $transformer = null;

        if (! is_object($related)) {
            return $related;
        }

        // if its a collection switch the object to the first item.
        if ($related instanceof Collection) {
            if ($related->count()) {
                $result = $result[0];
            } else {
                return [];
            }
        }

        $transformer = $this->resolveTransformer($result);

        // If no transformer was resolved.
        if (! $transformer) {
            return $related->toArray();
        }

        // if it has nested relations (equal to or more than 2 levels)
        if (count($nestedRelations) == 2) {
            // configure the remaining nested relations to the transformer.
            $transformer->with($nestedRelations[1]);
        }

        return $transformer->transform($related);
    }
protected function getRelatedTransformation($item, $relation)
    {
        // get nested relations separated by the dot notation.
        // we only get one relation at a time because recursion handles the remaining relations.
        $nestedRelations = explode('.', $relation, 2);
        $relation = $nestedRelations[0];

        $result = $item->{$relation};
        $related = $result;

        $transformer = null;

        if (! is_object($related)) {
            return $related;
        }

        // if its a collection switch the object to the first item.
        if ($related instanceof Collection) {
            if ($related->count()) {
                $result = $result[0];
            } else {
                return [];
            }
        }

        $transformer = $this->resolveTransformer($result);

        // If no transformer was resolved.
        if (! $transformer) {
            return $related->toArray();
        }

        // if it has nested relations (equal to or more than 2 levels)
        if (count($nestedRelations) == 2) {
            // configure the remaining nested relations to the transformer.
            $transformer->with($nestedRelations[1]);
        }

        return $transformer->transform($related);
    }
protected function getRelatedTransformation ( $ item , $ relation ) { // get nested relations separated by the dot notation. // we only get one relation at a time because recursion handles the remaining relations. $ nestedRelations = explode ( '.' , $ relation , 2 ) ; $ relation = $ nestedRelations [ 0 ] ; $ result = $ item -> { $ relation } ; $ related = $ result ; $ transformer = null ; if ( ! is_object ( $ related ) ) { return $ related ; } // if its a collection switch the object to the first item. if ( $ related instanceof Collection ) { if ( $ related -> count ( ) ) { $ result = $ result [ 0 ] ; } else { return [ ] ; } } $ transformer = $ this -> resolveTransformer ( $ result ) ; // If no transformer was resolved. if ( ! $ transformer ) { return $ related -> toArray ( ) ; } // if it has nested relations (equal to or more than 2 levels) if ( count ( $ nestedRelations ) == 2 ) { // configure the remaining nested relations to the transformer. $ transformer -> with ( $ nestedRelations [ 1 ] ) ; } return $ transformer -> transform ( $ related ) ; }
Resolves the transformation for the related model.

@param $item
@param $relation
@return mixed
Resolves the transformation for the related model .