whereRaw('LOWER(domain_name) = ?', [mb_strtolower($domainName)])->value('id'); if (! $domainId) { $serverId = $this->canonicalServerId(); if (! $serverId) { return; } $domainId = DB::table('dns_manager_domain')->insertGetId([ 'domain_name' => $domainName, 'dns_manager_server_id' => $serverId, // not a real provisioned DNS zone, just a billing placeholder created from WHMCS 'is_created' => 0, 'registrar_id' => $registrarId, 'created_at' => now(), 'updated_at' => now(), ]); } elseif ($registrarId !== null) { // don't clobber an existing registrar with an unresolved (null) one from a later re-sync DB::table('dns_manager_domain')->where('id', $domainId)->update(['registrar_id' => $registrarId]); } DB::table('dns_domain_user')->updateOrInsert( ['domain_id' => $domainId, 'user_id' => $customerId], ['created_at' => now(), 'updated_at' => now()] ); } private function canonicalServerId(): ?int { return self::$canonicalServerId ??= DB::table('dns_manager_servers') ->orderByRaw('CASE WHEN id = 1 THEN 0 ELSE 1 END') ->orderBy('id') ->value('id'); } }