src/Eloquent/Model.php
public function belongsToMany(
        $related,
        $table = null,
        $foreignPivotKey = null,
        $relatedPivotKey = null,
        $parentKey = null,
        $relatedKey = null,
        $relation = null
    ) {
        if (is_null($relation)) {
            $relation = $this->guessBelongsToManyRelation();
        }

        $instance = $this->setInstanceConnection($this->newRelatedInstance($related));

        $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey();

        $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey();

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

        $table = $this->getConnection()->db->prefix.$table;

        return new BelongsToMany($instance->newQuery(), $this, $table, $foreignPivotKey, $relatedPivotKey, $parentKey ?: $this->getKeyName(), $relatedKey ?: $instance->getKeyName(), $relation);
    }
public function belongsToMany(
        $related,
        $table = null,
        $foreignPivotKey = null,
        $relatedPivotKey = null,
        $parentKey = null,
        $relatedKey = null,
        $relation = null
    ) {
        if (is_null($relation)) {
            $relation = $this->guessBelongsToManyRelation();
        }

        $instance = $this->setInstanceConnection($this->newRelatedInstance($related));

        $foreignPivotKey = $foreignPivotKey ?: $this->getForeignKey();

        $relatedPivotKey = $relatedPivotKey ?: $instance->getForeignKey();

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

        $table = $this->getConnection()->db->prefix.$table;

        return new BelongsToMany($instance->newQuery(), $this, $table, $foreignPivotKey, $relatedPivotKey, $parentKey ?: $this->getKeyName(), $relatedKey ?: $instance->getKeyName(), $relation);
    }
public function belongsToMany ( $ related , $ table = null , $ foreignPivotKey = null , $ relatedPivotKey = null , $ parentKey = null , $ relatedKey = null , $ relation = null ) { if ( is_null ( $ relation ) ) { $ relation = $ this -> guessBelongsToManyRelation ( ) ; } $ instance = $ this -> setInstanceConnection ( $ this -> newRelatedInstance ( $ related ) ) ; $ foreignPivotKey = $ foreignPivotKey ? : $ this -> getForeignKey ( ) ; $ relatedPivotKey = $ relatedPivotKey ? : $ instance -> getForeignKey ( ) ; if ( is_null ( $ table ) ) { $ table = $ this -> joiningTable ( $ related ) ; } $ table = $ this -> getConnection ( ) -> db -> prefix . $ table ; return new BelongsToMany ( $ instance -> newQuery ( ) , $ this , $ table , $ foreignPivotKey , $ relatedPivotKey , $ parentKey ? : $ this -> getKeyName ( ) , $ relatedKey ? : $ instance -> getKeyName ( ) , $ relation ) ; }
Replace the original belongsToMany function to forward the connection name.

@param string $related
@param string $table
@param string $foreignPivotKey
@param string $relatedPivotKey
@param string $parentKey
@param string $relatedKey
@param string $relation
@return BelongsToMany
Replace the original belongsToMany function to forward the connection name .