You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I use the package in a Filament Admin project. I have my own Authentication Guard for the logins, which uses the Landlord database. The Tenants are also stored in the database with all parameters of a database connection. All Tenants use their own database and database connection.
I changed the SwitchDatabaseTask a little bit:
protected function setTenantConnectionDatabaseName(?IsTenant $tenant): void
{
$tenantConnectionName = $this->tenantDatabaseConnectionName();
if ($tenantConnectionName === $this->landlordDatabaseConnectionName()) {
throw InvalidConfiguration::tenantConnectionIsEmptyOrEqualsToLandlordConnection();
}
if (is_null(config("database.connections.{$tenantConnectionName}"))) {
throw InvalidConfiguration::tenantConnectionDoesNotExist($tenantConnectionName);
}
config([
"database.connections.{$tenantConnectionName}.database" => $tenant->database_name,
"database.connections.{$tenantConnectionName}.host" => $tenant->database_host,
"database.connections.{$tenantConnectionName}.username" => $tenant->database_user,
"database.connections.{$tenantConnectionName}.password" => decrypt($tenant->database_password),
]);
app('db')->extend($tenantConnectionName, function ($config, $name) use ($tenant) {
$config['database'] = $tenant->database_name;
$config['host'] = $tenant->database_host;
$config['username'] = $tenant->database_user;
$config['password'] = decrypt($tenant->database_password);
return app('db.factory')->make($config, $name);
});
DB::purge($tenantConnectionName);
// Octane will have an old `db` instance in the Model::$resolver.
Model::setConnectionResolver(app('db'));
}
When I try to use the Filament admin, I receive the given issue:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tenant_1.admins' doesn't exist (Connection: landlord, SQL: select * from `admins` where `email` = ...
So, by the connection, it seems it uses the right connection, but it is linked to a tenant database. I tried not to use the Switch database task, but the Spatie's Select Tenant Event handler, but no results.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I use the package in a Filament Admin project. I have my own Authentication Guard for the logins, which uses the Landlord database. The Tenants are also stored in the database with all parameters of a database connection. All Tenants use their own database and database connection.
I changed the
SwitchDatabaseTask
a little bit:When I try to use the Filament admin, I receive the given issue:
So, by the connection, it seems it uses the right connection, but it is linked to a tenant database. I tried not to use the Switch database task, but the Spatie's Select Tenant Event handler, but no results.
Beta Was this translation helpful? Give feedback.
All reactions