From 2b3466f95190d149061c7f7da54aa5c7ba0a6570 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 4 May 2026 11:48:55 +0200 Subject: [PATCH] Check the current DB name instead of configured one in harden() --- src/Bootstrappers/DatabaseTenancyBootstrapper.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Bootstrappers/DatabaseTenancyBootstrapper.php b/src/Bootstrappers/DatabaseTenancyBootstrapper.php index 30a55f73..ad713ce1 100644 --- a/src/Bootstrappers/DatabaseTenancyBootstrapper.php +++ b/src/Bootstrappers/DatabaseTenancyBootstrapper.php @@ -5,7 +5,6 @@ declare(strict_types=1); namespace Stancl\Tenancy\Bootstrappers; use Exception; -use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Facades\Schema; use RuntimeException; use Stancl\Tenancy\Contracts\TenancyBootstrapper; @@ -13,6 +12,7 @@ use Stancl\Tenancy\Contracts\Tenant; use Stancl\Tenancy\Database\Contracts\TenantWithDatabase; use Stancl\Tenancy\Database\DatabaseManager; use Stancl\Tenancy\Database\Exceptions\TenantDatabaseDoesNotExistException; +use Illuminate\Support\Facades\DB; class DatabaseTenancyBootstrapper implements TenancyBootstrapper { @@ -70,10 +70,9 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper protected function harden(Tenant $tenant): void { - /** @var TenantWithDatabase&Model $tenant */ - $dbName = $tenant->database()->getName(); + $dbName = DB::getDatabaseName(); - // 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()) ->where('data->tenancy_db_name', $dbName) ->exists()) {