protected function decideRelationColumns($relationName)
    {
        // https://stackoverflow.com/a/25472778/3113599
        $relationType = (new \ReflectionClass($this->modelObject->$relationName()))->getShortName();
        $selectColumns = [];

        switch ($relationType) {
            case 'BelongsTo':
                // Laravel 5.8 renamed getForeignKey() to getForeignKeyName()
                $methodName = method_exists($this->modelObject->$relationName(), 'getForeignKeyName') ?
                    'getForeignKeyName' :
                    'getForeignKey'
                ;

                $selectColumns[] = $this->modelObject->$relationName()->{$methodName}();
                break;
            case 'MorphTo':
                $selectColumns[] = $this->modelObject->$relationName()->getForeignKey();
                $selectColumns[] = $this->modelObject->$relationName()->getMorphType();
                break;
        }

        return $selectColumns;
    }
protected function decideRelationColumns($relationName)
    {
        // https://stackoverflow.com/a/25472778/3113599
        $relationType = (new \ReflectionClass($this->modelObject->$relationName()))->getShortName();
        $selectColumns = [];

        switch ($relationType) {
            case 'BelongsTo':
                // Laravel 5.8 renamed getForeignKey() to getForeignKeyName()
                $methodName = method_exists($this->modelObject->$relationName(), 'getForeignKeyName') ?
                    'getForeignKeyName' :
                    'getForeignKey'
                ;

                $selectColumns[] = $this->modelObject->$relationName()->{$methodName}();
                break;
            case 'MorphTo':
                $selectColumns[] = $this->modelObject->$relationName()->getForeignKey();
                $selectColumns[] = $this->modelObject->$relationName()->getMorphType();
                break;
        }

        return $selectColumns;
    }
protected function decideRelationColumns ( $ relationName ) { // https://stackoverflow.com/a/25472778/3113599 $ relationType = ( new \ ReflectionClass ( $ this -> modelObject -> $ relationName ( ) ) ) -> getShortName ( ) ; $ selectColumns = [ ] ; switch ( $ relationType ) { case 'BelongsTo' : // Laravel 5.8 renamed getForeignKey() to getForeignKeyName() $ methodName = method_exists ( $ this -> modelObject -> $ relationName ( ) , 'getForeignKeyName' ) ? 'getForeignKeyName' : 'getForeignKey' ; $ selectColumns [ ] = $ this -> modelObject -> $ relationName ( ) -> { $ methodName } ( ) ; break ; case 'MorphTo' : $ selectColumns [ ] = $ this -> modelObject -> $ relationName ( ) -> getForeignKey ( ) ; $ selectColumns [ ] = $ this -> modelObject -> $ relationName ( ) -> getMorphType ( ) ; break ; } return $ selectColumns ; }
Decides the columns to be used based on the relationship.

@param string Name of the relation

@return array
Decides the columns to be used based on the relationship .