protected function joinIntermediate(Model $parent, Relation $relation, $type)
    {
        if ($relation instanceof BelongsToMany) {
            $table = $relation->getTable();
            $fk = $relation->getQualifiedForeignPivotKeyName();
        } else {
            $table = $relation->getParent()->getTable();
            $fk = $relation->getQualifiedFirstKeyName();
        }

        $pk = $parent->getQualifiedKeyName();

        if (!$this->alreadyJoined($join = (new Join($this->query, $type, $table))->on($fk, '=', $pk))) {
            $this->query->joins[] = $join;
        }
    }
protected function joinIntermediate(Model $parent, Relation $relation, $type)
    {
        if ($relation instanceof BelongsToMany) {
            $table = $relation->getTable();
            $fk = $relation->getQualifiedForeignPivotKeyName();
        } else {
            $table = $relation->getParent()->getTable();
            $fk = $relation->getQualifiedFirstKeyName();
        }

        $pk = $parent->getQualifiedKeyName();

        if (!$this->alreadyJoined($join = (new Join($this->query, $type, $table))->on($fk, '=', $pk))) {
            $this->query->joins[] = $join;
        }
    }
protected function joinIntermediate ( Model $ parent , Relation $ relation , $ type ) { if ( $ relation instanceof BelongsToMany ) { $ table = $ relation -> getTable ( ) ; $ fk = $ relation -> getQualifiedForeignPivotKeyName ( ) ; } else { $ table = $ relation -> getParent ( ) -> getTable ( ) ; $ fk = $ relation -> getQualifiedFirstKeyName ( ) ; } $ pk = $ parent -> getQualifiedKeyName ( ) ; if ( ! $ this -> alreadyJoined ( $ join = ( new Join ( $ this -> query , $ type , $ table ) ) -> on ( $ fk , '=' , $ pk ) ) ) { $ this -> query -> joins [ ] = $ join ; } }
Join pivot or 'through' table.

@param  \Illuminate\Database\Eloquent\Model $parent
@param  \Illuminate\Database\Eloquent\Relations\Relation $relation
@param  string $type
@return void
Join pivot or through table .