connectToTenant(); $tenantSessionKey = $this->config->get('tenancy.rls.session_variable_name'); $this->database->statement("SET {$tenantSessionKey} = '{$tenant->getTenantKey()}'"); } public function revert(): void { $this->database->statement("RESET {$this->config->get('tenancy.rls.session_variable_name')}"); $this->tenantConnectionManager->reconnectToCentral(); } protected function connectToTenant(): void { $centralConnection = $this->config->get('tenancy.database.central_connection'); $this->tenantConnectionManager->purgeTenantConnection(); $tenantConnection = array_merge($this->config->get('database.connections.' . $centralConnection), [ 'username' => $this->config->get('tenancy.rls.user.username'), 'password' => $this->config->get('tenancy.rls.user.password'), ]); $this->config['database.connections.tenant'] = $tenantConnection; $this->tenantConnectionManager->setDefaultConnection('tenant'); } }