Skip to content

Multitenancy support #173

@pxlrbt

Description

@pxlrbt

Hey,

would support for multi-tenancy be something you'd add for v2?

In v1 this is a bit hacky. I need to overwrite the initial migration, the table and storage path. I just checked out v2, but I don't see an easy way to tap into the code to add this functionality.

The main issue is that bootOrbital() ran before middlewares so no tenants are identified.

My code for v1:

public function migrate()
{
    // Migrate central
    static::$orbitalPath = base_path('storage/app/pages');
    $this->setTable('pages');
    $this->parentMigrate();

    // Migrate Tenants
    $i = 1;
    while (file_exists($path = base_path('storage/tenant'.$i.'/app/pages'))) {
        static::$orbitalPath = $path;
        $this->setTable('pages_'.$i);

        $this->parentMigrate();
        $i++;
    }
}

public function getTable(): string
{
    return $this->table ?? (tenant() === null ? 'pages' : 'pages_'.tenant()->id);
}

public static function getOrbitalPath()
{
    return static::$orbitalPath ?? storage_path('app/pages').DIRECTORY_SEPARATOR.static::getOrbitalName();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions