argument('tenantCode'); if (Tenant::query()->where('id', $tenantCode)->exists()) { $this->error("tenant $tenantCode already exists"); return; } $this->info("creating tenant $tenantCode"); $tenant = [ 'id' => $tenantCode, 'tenancy_db_username' => $this->option('db-username') ?? $tenantCode, 'tenancy_db_password' => $this->option('db-password') ?? $tenantCode, ]; // 默认值为 tenancy.database.prefix配置 + 租户 ID +tenancy.database.suffix配置 if (!empty($this->option('db-name'))) { $tenant['tenancy_db_name'] = $this->option('db-name'); } // 默认值为 tenancy.database.template_connection配置 if (!empty($this->option('db-connection'))) { $tenant['tenancy_db_connection'] = $this->option('db-connection'); } try { Tenant::create($tenant); } catch (\Exception $e) { // TODO: handle exception $this->error("create tenant $tenantCode fail:" . $e->getMessage()); } $this->info("create tenant $tenantCode success"); } }