mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
[2.2.4] [WIP] Respect custom connections when creating database (#244)
* Add TenantDatabaseManager::setConnection() * Apply fixes from StyleCI
This commit is contained in:
parent
5145b1f13e
commit
fed8c0f9d1
4 changed files with 40 additions and 5 deletions
|
|
@ -8,6 +8,7 @@ use Closure;
|
|||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Database\DatabaseManager as BaseDatabaseManager;
|
||||
use Illuminate\Foundation\Application;
|
||||
use Stancl\Tenancy\Contracts\Future\CanSetConnection;
|
||||
use Stancl\Tenancy\Contracts\TenantDatabaseManager;
|
||||
use Stancl\Tenancy\Exceptions\DatabaseManagerNotRegisteredException;
|
||||
use Stancl\Tenancy\Exceptions\TenantDatabaseAlreadyExistsException;
|
||||
|
|
@ -226,7 +227,7 @@ class DatabaseManager
|
|||
*/
|
||||
public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
{
|
||||
$driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));
|
||||
$driver = $this->getDriver($this->getBaseConnection($connectionName = $tenant->getConnectionName()));
|
||||
|
||||
$databaseManagers = $this->app['config']['tenancy.database_managers'];
|
||||
|
||||
|
|
@ -234,6 +235,12 @@ class DatabaseManager
|
|||
throw new DatabaseManagerNotRegisteredException($driver);
|
||||
}
|
||||
|
||||
return $this->app[$databaseManagers[$driver]];
|
||||
$databaseManager = $this->app[$databaseManagers[$driver]];
|
||||
|
||||
if ($connectionName !== 'tenant' && $databaseManager instanceof CanSetConnection) {
|
||||
$databaseManager->setConnection($this->database->connection($connectionName));
|
||||
}
|
||||
|
||||
return $databaseManager;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue