src/Models/CmsModel.php
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relation name was given, we will use this debug backtrace to extract
        // the calling method's name and use that as the relationship name as most
        // of the time this will be what we desire to use for the relationships.
        if (is_null($relation)) {
            list($current, $caller) = debug_backtrace(false, 2);

            $relation = $caller['function'];
        }

        $specialType = $this->getCmsSpecialRelationType($relation);

        // If no foreign key was supplied, we can use a backtrace to guess the proper
        // foreign key name by using the name of the relationship function, which
        // when combined with an "_id" should conventionally match the columns.
        if (is_null($foreignKey)) {
            if ($specialType === self::RELATION_TYPE_CATEGORY) {
                $foreignKey = config('pxlcms.relations.categories.keys.category');
            } else {
                $foreignKey = Str::snake($relation);
            }
        }

        // If the relation name is the same (casing aside) as the foreign key attribute,
        // we must make sure that the foreign key property is at least a key in the
        // attributes array. If it is not, there will be recursive lookup problems
        // where the attribute is never resolved and 'property does not exist' exceptions occur.
        if (    snake_case($relation) == $foreignKey
            &&  ! array_key_exists($foreignKey, $this->attributes)
        ) {
            $this->attributes[ $foreignKey ] = null;
        }

        /** @var Builder $belongsTo */
        $belongsTo = parent::belongsTo($related, $foreignKey, $otherKey, $relation);

        // category relation must be filtered by module id
        if ($specialType === self::RELATION_TYPE_CATEGORY) {
            $belongsTo->where(
                config('pxlcms.relations.categories.keys.module'),
                $this->getModuleNumber()
            );
        }

        return $belongsTo;
    }
public function belongsTo($related, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relation name was given, we will use this debug backtrace to extract
        // the calling method's name and use that as the relationship name as most
        // of the time this will be what we desire to use for the relationships.
        if (is_null($relation)) {
            list($current, $caller) = debug_backtrace(false, 2);

            $relation = $caller['function'];
        }

        $specialType = $this->getCmsSpecialRelationType($relation);

        // If no foreign key was supplied, we can use a backtrace to guess the proper
        // foreign key name by using the name of the relationship function, which
        // when combined with an "_id" should conventionally match the columns.
        if (is_null($foreignKey)) {
            if ($specialType === self::RELATION_TYPE_CATEGORY) {
                $foreignKey = config('pxlcms.relations.categories.keys.category');
            } else {
                $foreignKey = Str::snake($relation);
            }
        }

        // If the relation name is the same (casing aside) as the foreign key attribute,
        // we must make sure that the foreign key property is at least a key in the
        // attributes array. If it is not, there will be recursive lookup problems
        // where the attribute is never resolved and 'property does not exist' exceptions occur.
        if (    snake_case($relation) == $foreignKey
            &&  ! array_key_exists($foreignKey, $this->attributes)
        ) {
            $this->attributes[ $foreignKey ] = null;
        }

        /** @var Builder $belongsTo */
        $belongsTo = parent::belongsTo($related, $foreignKey, $otherKey, $relation);

        // category relation must be filtered by module id
        if ($specialType === self::RELATION_TYPE_CATEGORY) {
            $belongsTo->where(
                config('pxlcms.relations.categories.keys.module'),
                $this->getModuleNumber()
            );
        }

        return $belongsTo;
    }
public function belongsTo ( $ related , $ foreignKey = null , $ otherKey = null , $ relation = null ) { // If no relation name was given, we will use this debug backtrace to extract // the calling method's name and use that as the relationship name as most // of the time this will be what we desire to use for the relationships. if ( is_null ( $ relation ) ) { list ( $ current , $ caller ) = debug_backtrace ( false , 2 ) ; $ relation = $ caller [ 'function' ] ; } $ specialType = $ this -> getCmsSpecialRelationType ( $ relation ) ; // If no foreign key was supplied, we can use a backtrace to guess the proper // foreign key name by using the name of the relationship function, which // when combined with an "_id" should conventionally match the columns. if ( is_null ( $ foreignKey ) ) { if ( $ specialType === self :: RELATION_TYPE_CATEGORY ) { $ foreignKey = config ( 'pxlcms.relations.categories.keys.category' ) ; } else { $ foreignKey = Str :: snake ( $ relation ) ; } } // If the relation name is the same (casing aside) as the foreign key attribute, // we must make sure that the foreign key property is at least a key in the // attributes array. If it is not, there will be recursive lookup problems // where the attribute is never resolved and 'property does not exist' exceptions occur. if ( snake_case ( $ relation ) == $ foreignKey && ! array_key_exists ( $ foreignKey , $ this -> attributes ) ) { $ this -> attributes [ $ foreignKey ] = null ; } /** @var Builder $belongsTo */ $ belongsTo = parent :: belongsTo ( $ related , $ foreignKey , $ otherKey , $ relation ) ; // category relation must be filtered by module id if ( $ specialType === self :: RELATION_TYPE_CATEGORY ) { $ belongsTo -> where ( config ( 'pxlcms.relations.categories.keys.module' ) , $ this -> getModuleNumber ( ) ) ; } return $ belongsTo ; }
Override for different naming convention

@param  string $related
@param  string $foreignKey
@param  string $otherKey
@param  string $relation
@return \Illuminate\Database\Eloquent\Relations\BelongsTo
Override for different naming convention