mirror of
https://github.com/archtechx/tenancy.git
synced 2026-05-06 15:24:03 +00:00
Check the current DB name instead of configured one in harden()
This commit is contained in:
parent
405aaafb4e
commit
2b3466f951
1 changed files with 3 additions and 4 deletions
|
|
@ -5,7 +5,6 @@ declare(strict_types=1);
|
||||||
namespace Stancl\Tenancy\Bootstrappers;
|
namespace Stancl\Tenancy\Bootstrappers;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
use Illuminate\Support\Facades\Schema;
|
||||||
use RuntimeException;
|
use RuntimeException;
|
||||||
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
|
||||||
|
|
@ -13,6 +12,7 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
use Stancl\Tenancy\Database\DatabaseManager;
|
use Stancl\Tenancy\Database\DatabaseManager;
|
||||||
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException;
|
use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||||
{
|
{
|
||||||
|
|
@ -70,10 +70,9 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected function harden(Tenant $tenant): void
|
protected function harden(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
/** @var TenantWithDatabase&Model $tenant */
|
$dbName = DB::getDatabaseName();
|
||||||
$dbName = $tenant->database()->getName();
|
|
||||||
|
|
||||||
// Check if the current database is unique (i.e. no other tenant uses this database)
|
// Check if any other tenant uses this tenant's database
|
||||||
if ($tenant::where($tenant->getTenantKeyName(), '!=', $tenant->getTenantKey())
|
if ($tenant::where($tenant->getTenantKeyName(), '!=', $tenant->getTenantKey())
|
||||||
->where('data->tenancy_db_name', $dbName)
|
->where('data->tenancy_db_name', $dbName)
|
||||||
->exists()) {
|
->exists()) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue