From 565bc41bf33766507e50a81a5657a8f48b30fb47 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Tue, 9 Jun 2026 09:02:31 +0200 Subject: [PATCH] Use a more specific central db check in the hardening feature Instead of just checking the presence of the tenants table on the current connection to determine if the table is/isn't tenant, check the current database's name, and if it's the central DB name, throw the runtime exception. --- src/Bootstrappers/DatabaseTenancyBootstrapper.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Bootstrappers/DatabaseTenancyBootstrapper.php b/src/Bootstrappers/DatabaseTenancyBootstrapper.php index d6becad2..20848bd5 100644 --- a/src/Bootstrappers/DatabaseTenancyBootstrapper.php +++ b/src/Bootstrappers/DatabaseTenancyBootstrapper.php @@ -100,8 +100,12 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper throw new RuntimeException('Tenant cannot use a database of another tenant.'); } - // Check if the current database doesn't have the tenants table (i.e. it's not the central database) - if (Schema::hasTable($tenant->getTable())) { + // Check if the current database is not the central database + $centralDbName = DB::connection( + config('tenancy.database.central_connection', 'central') + )->getDatabaseName(); + + if ($dbName === $centralDbName) { throw new RuntimeException('Tenant cannot use the central database.'); } }