mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
wip
This commit is contained in:
parent
50a77ee826
commit
a9c37d1535
8 changed files with 24 additions and 25 deletions
|
|
@ -37,7 +37,7 @@ class DatabaseManager
|
|||
*/
|
||||
public function connect(Tenant $tenant)
|
||||
{
|
||||
$this->createTenantConnection($tenant);
|
||||
$this->createTenantConnection($tenant->getDatabaseName(), $tenant->getConnectionName());
|
||||
$this->switchConnection($tenant->getConnectionName());
|
||||
}
|
||||
|
||||
|
|
@ -54,14 +54,12 @@ class DatabaseManager
|
|||
/**
|
||||
* Create the tenant database connection.
|
||||
*
|
||||
* @param Tenant $tenant
|
||||
* @param string $databaseName
|
||||
* @param string $connectionName
|
||||
* @return void
|
||||
*/
|
||||
public function createTenantConnection(Tenant $tenant)
|
||||
public function createTenantConnection($databaseName, $connectionName)
|
||||
{
|
||||
$databaseName = $tenant->getDatabaseName();
|
||||
$connectionName = $tenant->getConnectionName();
|
||||
|
||||
// Create the database connection.
|
||||
$based_on = $this->app['config']['tenancy.database.based_on'] ?? $this->originalDefaultConnectionName;
|
||||
$this->app['config']["database.connections.$connectionName"] = $this->app['config']['database.connections.' . $based_on];
|
||||
|
|
@ -129,7 +127,7 @@ class DatabaseManager
|
|||
|
||||
protected function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
{
|
||||
$this->createTenantConnection($tenant);
|
||||
$this->createTenantConnection($tenant->getDatabaseName(), $tenant->getConnectionName());
|
||||
$driver = $this->getDriver($tenant->getConnectionName());
|
||||
|
||||
$databaseManagers = $this->app['config']['tenancy.database_managers'];
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class TelescopeTags implements Feature
|
|||
if (in_array('tenancy', optional(request()->route())->middleware() ?? [])) {
|
||||
$tags = array_merge($tags, [
|
||||
'tenant:' . tenant('id'),
|
||||
'domain:' . tenant('domain'),
|
||||
// 'domain:' . tenant('domain'), todo?
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,13 +44,13 @@ class QueueTenancyBootstrapper implements TenancyBootstrapper
|
|||
return [];
|
||||
}
|
||||
|
||||
[$id, $domain] = tenant()->get(['id', 'domain']);
|
||||
$id = tenant()->get('id');
|
||||
|
||||
return [
|
||||
'tenant_id' => $id,
|
||||
'tags' => [
|
||||
"tenant:$id",
|
||||
"domain:$domain",
|
||||
// todo domain?
|
||||
],
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,8 +97,9 @@ class TenantManager
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function init(string $domain): self
|
||||
public function init(string $domain = null): self
|
||||
{
|
||||
$domain = $domain ?? request()->getHost();
|
||||
$this->initializeTenancy($this->findByDomain($domain));
|
||||
|
||||
return $this;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue