src/Builder.php
public function join($relationName, $type = 'inner', $where = false)
    {
        $this->joined[] = $relationName;

        $relation = $this->getRelation($relationName);

        if ($relation instanceof BelongsTo) {
            $this->query->join(
                $relation->getRelated()->getTable(),
                $this->model->getTable().'.'.$relation->getForeignKey(),
                '=',
                $relation->getRelated()->getTable().'.'.$relation->getOtherKey(),
                $type,
                $where
            );
        } elseif ($relation instanceof BelongsToMany) {
            $this->query->join(
                $relation->getTable(),
                $relation->getQualifiedParentKeyName(),
                '=',
                $relation->getForeignKey(),
                $type,
                $where
            );

            $this->query->join(
                $relation->getRelated()->getTable(),
                $relation->getRelated()->getTable().'.'.$relation->getRelated()->getKeyName(),
                '=',
                $relation->getOtherKey(),
                $type,
                $where
            );
        } else {
            $this->query->join(
                $relation->getRelated()->getTable(),
                $relation->getQualifiedParentKeyName(),
                '=',
                $relation->getForeignKey(),
                $type,
                $where
            );
        }

        $relation_columns = $this->query
            ->getConnection()
            ->getSchemaBuilder()
            ->getColumnListing($relation->getRelated()->getTable());

        array_walk($relation_columns, function (&$column) use ($relation, $relationName) {
            $column = $relation->getRelated()->getTable().'.'.$column.' as '.$relationName.'.'.$column;
        });

        $this->query->addSelect(array_merge([$this->model->getTable().'.*'], $relation_columns));

        return $this;
    }
public function join($relationName, $type = 'inner', $where = false)
    {
        $this->joined[] = $relationName;

        $relation = $this->getRelation($relationName);

        if ($relation instanceof BelongsTo) {
            $this->query->join(
                $relation->getRelated()->getTable(),
                $this->model->getTable().'.'.$relation->getForeignKey(),
                '=',
                $relation->getRelated()->getTable().'.'.$relation->getOtherKey(),
                $type,
                $where
            );
        } elseif ($relation instanceof BelongsToMany) {
            $this->query->join(
                $relation->getTable(),
                $relation->getQualifiedParentKeyName(),
                '=',
                $relation->getForeignKey(),
                $type,
                $where
            );

            $this->query->join(
                $relation->getRelated()->getTable(),
                $relation->getRelated()->getTable().'.'.$relation->getRelated()->getKeyName(),
                '=',
                $relation->getOtherKey(),
                $type,
                $where
            );
        } else {
            $this->query->join(
                $relation->getRelated()->getTable(),
                $relation->getQualifiedParentKeyName(),
                '=',
                $relation->getForeignKey(),
                $type,
                $where
            );
        }

        $relation_columns = $this->query
            ->getConnection()
            ->getSchemaBuilder()
            ->getColumnListing($relation->getRelated()->getTable());

        array_walk($relation_columns, function (&$column) use ($relation, $relationName) {
            $column = $relation->getRelated()->getTable().'.'.$column.' as '.$relationName.'.'.$column;
        });

        $this->query->addSelect(array_merge([$this->model->getTable().'.*'], $relation_columns));

        return $this;
    }
Add a join clause to the query.

@param string $relation
@param string $type
@param bool   $where

@return $this