1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-21 10:44:03 +00:00

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.
This commit is contained in:
lukinovec 2026-06-09 09:02:31 +02:00
parent 48b8aac42d
commit 565bc41bf3

View file

@ -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.');
}
}