protected function mergeRelations(&$resource, $input)
    {
        $existingNames = [];

        foreach ($resource->relations as $relation) {
            $existingNames[] = $relation->getName();
        }
        $mergeRelations = 0;
        foreach ($input->relations as $relation) {
            $newRelation = ForeignRelationship::fromString($relation);

            if (is_null($newRelation)) {
                continue;
            }
            if (!empty($newRelation->name) && in_array($newRelation->name, $existingNames)) {
                $this->warn('The relation "' . $newRelation->name . '" already exists in the file.');
                continue;
            }

            $resource->relations[] = $newRelation;
            $existingNames[] = $newRelation->name;

            $mergeRelations++;
        }

        return $mergeRelations;
    }
protected function mergeRelations(&$resource, $input)
    {
        $existingNames = [];

        foreach ($resource->relations as $relation) {
            $existingNames[] = $relation->getName();
        }
        $mergeRelations = 0;
        foreach ($input->relations as $relation) {
            $newRelation = ForeignRelationship::fromString($relation);

            if (is_null($newRelation)) {
                continue;
            }
            if (!empty($newRelation->name) && in_array($newRelation->name, $existingNames)) {
                $this->warn('The relation "' . $newRelation->name . '" already exists in the file.');
                continue;
            }

            $resource->relations[] = $newRelation;
            $existingNames[] = $newRelation->name;

            $mergeRelations++;
        }

        return $mergeRelations;
    }
protected function mergeRelations ( & $ resource , $ input ) { $ existingNames = [ ] ; foreach ( $ resource -> relations as $ relation ) { $ existingNames [ ] = $ relation -> getName ( ) ; } $ mergeRelations = 0 ; foreach ( $ input -> relations as $ relation ) { $ newRelation = ForeignRelationship :: fromString ( $ relation ) ; if ( is_null ( $ newRelation ) ) { continue ; } if ( ! empty ( $ newRelation -> name ) && in_array ( $ newRelation -> name , $ existingNames ) ) { $ this -> warn ( 'The relation "' . $ newRelation -> name . '" already exists in the file.' ) ; continue ; } $ resource -> relations [ ] = $ newRelation ; $ existingNames [ ] = $ newRelation -> name ; $ mergeRelations ++ ; } return $ mergeRelations ; }
Merges the relation to the existing resources.

@param CrestApps\CodeGenerator\Models\Resource &$resource
@param (object) $input

@return int
Merges the relation to the existing resources .