mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 08:44:04 +00:00
TenantDatabaseDoesNotExistException
This commit is contained in:
parent
d899dcfcce
commit
d4d6c747d2
3 changed files with 20 additions and 1 deletions
|
|
@ -182,7 +182,7 @@ class DatabaseManager
|
|||
* @param Tenant $tenant
|
||||
* @return TenantDatabaseManager
|
||||
*/
|
||||
protected function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
public function getTenantDatabaseManager(Tenant $tenant): TenantDatabaseManager
|
||||
{
|
||||
$driver = $this->getDriver($this->getBaseConnection($tenant->getConnectionName()));
|
||||
|
||||
|
|
|
|||
13
src/Exceptions/TenantDatabaseDoesNotExistException.php
Normal file
13
src/Exceptions/TenantDatabaseDoesNotExistException.php
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class TenantDatabaseDoesNotExistException extends Exception
|
||||
{
|
||||
public function __construct($database)
|
||||
{
|
||||
parent::__construct("Database $database does not exist.");
|
||||
}
|
||||
}
|
||||
|
|
@ -6,6 +6,7 @@ namespace Stancl\Tenancy\TenancyBootstrappers;
|
|||
|
||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||
use Stancl\Tenancy\DatabaseManager;
|
||||
use Stancl\Tenancy\Exceptions\TenantDatabaseDoesNotExistException;
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||
|
|
@ -20,6 +21,11 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
|||
|
||||
public function start(Tenant $tenant)
|
||||
{
|
||||
$database = $tenant->getDatabaseName();
|
||||
if (! $this->database->getTenantDatabaseManager($tenant)->databaseExists($database)) {
|
||||
throw new TenantDatabaseDoesNotExistException($database);
|
||||
}
|
||||
|
||||
$this->database->connect($tenant);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue