protected function transformRelations(array $transformed)
    {
        // Iterate through all relations
        foreach ($this->model->getRelations() as $relationKey => $relation) {
            $transformedRelationKey = $this->formatKeyCase($relationKey);

            // Skip Pivot
            if ($relation instanceof \Illuminate\Database\Eloquent\Relations\Pivot) {
                continue;
            }

            // Transform Collection
            elseif ($relation instanceof \Illuminate\Database\Eloquent\Collection) {
                if (count($relation->getIterator()) > 0) {
                    $relationModel = $relation->first();
                    $relationTransformer = $relationModel::getTransformer();

                    // Transform related model collection
                    if ($this->model->$relationKey) {
                        // Create empty array for relation
                        $transformed[$transformedRelationKey] = [];

                        foreach ($relation->getIterator() as $key => $relatedModel) {
                            // Replace the related models with their transformed selves
                            $transformedRelatedModel = $relationTransformer->transform($relatedModel);

                            // We don't really care about pivot information at this stage
                            if (isset($transformedRelatedModel['pivot'])) {
                                unset($transformedRelatedModel['pivot']);
                            }

                            // Add transformed model to relation array
                            $transformed[$transformedRelationKey][] = $transformedRelatedModel;
                        }
                    }
                }
            }

            // Transformed related model
            elseif ($relation instanceof RestfulModel) {
                // Get transformer of relation model
                $relationTransformer = $relation::getTransformer();

                if ($this->model->$relationKey) {
                    $transformed[$transformedRelationKey] = $relationTransformer->transform($this->model->$relationKey);
                }
            }
        }

        return $transformed;
    }
protected function transformRelations(array $transformed)
    {
        // Iterate through all relations
        foreach ($this->model->getRelations() as $relationKey => $relation) {
            $transformedRelationKey = $this->formatKeyCase($relationKey);

            // Skip Pivot
            if ($relation instanceof \Illuminate\Database\Eloquent\Relations\Pivot) {
                continue;
            }

            // Transform Collection
            elseif ($relation instanceof \Illuminate\Database\Eloquent\Collection) {
                if (count($relation->getIterator()) > 0) {
                    $relationModel = $relation->first();
                    $relationTransformer = $relationModel::getTransformer();

                    // Transform related model collection
                    if ($this->model->$relationKey) {
                        // Create empty array for relation
                        $transformed[$transformedRelationKey] = [];

                        foreach ($relation->getIterator() as $key => $relatedModel) {
                            // Replace the related models with their transformed selves
                            $transformedRelatedModel = $relationTransformer->transform($relatedModel);

                            // We don't really care about pivot information at this stage
                            if (isset($transformedRelatedModel['pivot'])) {
                                unset($transformedRelatedModel['pivot']);
                            }

                            // Add transformed model to relation array
                            $transformed[$transformedRelationKey][] = $transformedRelatedModel;
                        }
                    }
                }
            }

            // Transformed related model
            elseif ($relation instanceof RestfulModel) {
                // Get transformer of relation model
                $relationTransformer = $relation::getTransformer();

                if ($this->model->$relationKey) {
                    $transformed[$transformedRelationKey] = $relationTransformer->transform($this->model->$relationKey);
                }
            }
        }

        return $transformed;
    }
protected function transformRelations ( array $ transformed ) { // Iterate through all relations foreach ( $ this -> model -> getRelations ( ) as $ relationKey => $ relation ) { $ transformedRelationKey = $ this -> formatKeyCase ( $ relationKey ) ; // Skip Pivot if ( $ relation instanceof \ Illuminate \ Database \ Eloquent \ Relations \ Pivot ) { continue ; } // Transform Collection elseif ( $ relation instanceof \ Illuminate \ Database \ Eloquent \ Collection ) { if ( count ( $ relation -> getIterator ( ) ) > 0 ) { $ relationModel = $ relation -> first ( ) ; $ relationTransformer = $ relationModel :: getTransformer ( ) ; // Transform related model collection if ( $ this -> model -> $ relationKey ) { // Create empty array for relation $ transformed [ $ transformedRelationKey ] = [ ] ; foreach ( $ relation -> getIterator ( ) as $ key => $ relatedModel ) { // Replace the related models with their transformed selves $ transformedRelatedModel = $ relationTransformer -> transform ( $ relatedModel ) ; // We don't really care about pivot information at this stage if ( isset ( $ transformedRelatedModel [ 'pivot' ] ) ) { unset ( $ transformedRelatedModel [ 'pivot' ] ) ; } // Add transformed model to relation array $ transformed [ $ transformedRelationKey ] [ ] = $ transformedRelatedModel ; } } } } // Transformed related model elseif ( $ relation instanceof RestfulModel ) { // Get transformer of relation model $ relationTransformer = $ relation :: getTransformer ( ) ; if ( $ this -> model -> $ relationKey ) { $ transformed [ $ transformedRelationKey ] = $ relationTransformer -> transform ( $ this -> model -> $ relationKey ) ; } } } return $ transformed ; }
Do relation transformations

@param array $transformed
@return array $transformed
Do relation transformations