Skip to content

Commit b906a72

Browse files
committed
make sure subdomain doesn't already exist on cloudflare
1 parent 6e80392 commit b906a72

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

subdomains/src/Models/Subdomain.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ public function upsertOnCloudflare(): void
6262
throw new Exception('Server has no allocation');
6363
}
6464

65+
$response = Http::cloudflare()->get("zones/{$this->domain->cloudflare_id}/dns_records/$this->cloudflare_id", ['search' => $this->name])->json();
66+
67+
if ($response['success']) {
68+
if (!empty($response['result'])) {
69+
throw new Exception('A subdomain with that name already exists');
70+
}
71+
} else {
72+
if ($response['errors'] && count($response['errors']) > 0) {
73+
throw new Exception($response['errors'][0]['message']);
74+
}
75+
}
76+
6577
$payload = [
6678
'name' => $this->name,
6779
'type' => $this->record_type,

0 commit comments

Comments
 (0)