Description
Versions:
- ide-helper Version: 2.9.0
- Laravel Version: 8.x
- PHP Version: 8.0
Description:
We have a multi-tenant application where models are split in 2 DB connections : system (app DB) and tenant (each customer has one)
Models on the tenant database do not have their attributes discovered from the database.
Package used to manage tenancy is hyn-multitenant which basically dynamically builds the Laravel DB connection information depending on the active tenant (which could be determined by the subdomain for instance or programmatically)
Issue
The code linked below does not get the proper database which should match a tenant database
laravel-ide-helper/src/Console/ModelsCommand.php
Lines 418 to 436 in f0959c1
$database stays null
Request
We should have a mecanism to allow discovery of those attributes.
One possible way to allow that could be to have a configuration entry where we could override the database according to the connection name.
Something like
'db_mapping'=> [
// connection => database name
'system' => 'homestead',
'tenant' => 'my_tenant',
],
Then code to get the database could be fixed liked that:
$connectionName = $model->getConnection()->getName();
$database = config("ide-helper.db_mapping.$connectionName");
if (strpos($table, '.')) {
[$database, $table] = explode('.', $table);
}
I have tested that on our project. There should be no difference in previous behaviour if the configuration is not specified.
Any thoughts?