src/Models/CmsModel.php
public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relationship name was passed, we will pull backtraces to get the
        // name of the calling function. We will use that function name as the
        // title of this relation since that is a great convention to apply.
        if (is_null($relation)) {
            $relation = $this->getBelongsToManyCaller();
        }

        $foreignKey = $foreignKey ?: $this->getCmsReferenceKeyForRelation($relation);
        $otherKey   = $otherKey   ?: $this->getCmsReferenceKeyForRelation($relation, true);

        if (is_null($table)) {
            $table = $this->getCmsJoiningTable();
        }

        $fieldId = $this->getCmsReferenceFieldId($relation);
        if (empty($fieldId)) {
            throw new InvalidArgumentException("No 'field' id configured for relation/reference: '{$relation}'!");
        }

        // originally, it was possible to just get the parent's BelongsToMany instance, but
        // to avoid problems when saving on the relationship, we need a specialized extension
        // of the relation class for the CMS.
        //$belongsToMany = parent::belongsToMany($related, $table, $foreignKey, $otherKey);

        /** @var Model $instance */
        $instance = new $related;

        $query = $instance->newQuery();

        $belongsToMany = new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation, $fieldId);

        // add constraints
        $belongsToMany->wherePivot(config('pxlcms.relations.references.keys.field', 'from_field_id'), $fieldId);

        return $belongsToMany;
    }
public function belongsToMany($related, $table = null, $foreignKey = null, $otherKey = null, $relation = null)
    {
        // If no relationship name was passed, we will pull backtraces to get the
        // name of the calling function. We will use that function name as the
        // title of this relation since that is a great convention to apply.
        if (is_null($relation)) {
            $relation = $this->getBelongsToManyCaller();
        }

        $foreignKey = $foreignKey ?: $this->getCmsReferenceKeyForRelation($relation);
        $otherKey   = $otherKey   ?: $this->getCmsReferenceKeyForRelation($relation, true);

        if (is_null($table)) {
            $table = $this->getCmsJoiningTable();
        }

        $fieldId = $this->getCmsReferenceFieldId($relation);
        if (empty($fieldId)) {
            throw new InvalidArgumentException("No 'field' id configured for relation/reference: '{$relation}'!");
        }

        // originally, it was possible to just get the parent's BelongsToMany instance, but
        // to avoid problems when saving on the relationship, we need a specialized extension
        // of the relation class for the CMS.
        //$belongsToMany = parent::belongsToMany($related, $table, $foreignKey, $otherKey);

        /** @var Model $instance */
        $instance = new $related;

        $query = $instance->newQuery();

        $belongsToMany = new BelongsToMany($query, $this, $table, $foreignKey, $otherKey, $relation, $fieldId);

        // add constraints
        $belongsToMany->wherePivot(config('pxlcms.relations.references.keys.field', 'from_field_id'), $fieldId);

        return $belongsToMany;
    }
public function belongsToMany ( $ related , $ table = null , $ foreignKey = null , $ otherKey = null , $ relation = null ) { // If no relationship name was passed, we will pull backtraces to get the // name of the calling function. We will use that function name as the // title of this relation since that is a great convention to apply. if ( is_null ( $ relation ) ) { $ relation = $ this -> getBelongsToManyCaller ( ) ; } $ foreignKey = $ foreignKey ? : $ this -> getCmsReferenceKeyForRelation ( $ relation ) ; $ otherKey = $ otherKey ? : $ this -> getCmsReferenceKeyForRelation ( $ relation , true ) ; if ( is_null ( $ table ) ) { $ table = $ this -> getCmsJoiningTable ( ) ; } $ fieldId = $ this -> getCmsReferenceFieldId ( $ relation ) ; if ( empty ( $ fieldId ) ) { throw new InvalidArgumentException ( "No 'field' id configured for relation/reference: '{$relation}'!" ) ; } // originally, it was possible to just get the parent's BelongsToMany instance, but // to avoid problems when saving on the relationship, we need a specialized extension // of the relation class for the CMS. //$belongsToMany = parent::belongsToMany($related, $table, $foreignKey, $otherKey); /** @var Model $instance */ $ instance = new $ related ; $ query = $ instance -> newQuery ( ) ; $ belongsToMany = new BelongsToMany ( $ query , $ this , $ table , $ foreignKey , $ otherKey , $ relation , $ fieldId ) ; // add constraints $ belongsToMany -> wherePivot ( config ( 'pxlcms.relations.references.keys.field' , 'from_field_id' ) , $ fieldId ) ; return $ belongsToMany ; }
Override for special cms_m_references 'pivot' table

@param  string $related
@param  string $table
@param  string $foreignKey
@param  string $otherKey
@param  string $relation
@return \Illuminate\Database\Eloquent\Relations\BelongsToMany
Override for special cms_m_references pivot table