We currently have a structure where each of our tenants has their own database, we also have one system database where we store the tenant organizations, almost everything in the application is based on this Tenant model which lives in the system database, and it has a bunch of relations connected to it on the tenant connection.
The way this tenant connection is described is as follows:
'tenant' => [
'driver' => 'mysql',
'url' => env('DB_URL'),
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_TENANT', 'tenant_001'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'options' => extension_loaded('pdo_mysql') ? array_filter([
PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
]) : [],
],
We then have some code on the Tenant model to set up the tenant connection