mirror of
https://github.com/archtechx/tenancy.git
synced 2026-06-21 11:24:03 +00:00
Determine data column and internal prefix dynamically instead of hardcoding in harden()
This commit is contained in:
parent
6e82a9ee55
commit
b4244be658
1 changed files with 2 additions and 1 deletions
|
|
@ -71,11 +71,12 @@ class DatabaseTenancyBootstrapper implements TenancyBootstrapper
|
||||||
|
|
||||||
protected function harden(Tenant $tenant): void
|
protected function harden(Tenant $tenant): void
|
||||||
{
|
{
|
||||||
|
/** @var \Stancl\Tenancy\Database\Models\Tenant $tenant */
|
||||||
$dbName = DB::getDatabaseName();
|
$dbName = DB::getDatabaseName();
|
||||||
|
|
||||||
// Check if any other tenant uses this tenant's 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($tenant::getDataColumn() . '->' . $tenant->internalPrefix() . 'db_name', $dbName)
|
||||||
->exists()) {
|
->exists()) {
|
||||||
throw new RuntimeException('Tenant cannot use a database of another tenant.');
|
throw new RuntimeException('Tenant cannot use a database of another tenant.');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue