Fix: Private key with ID 2 on dev

This commit is contained in:
peaklabs-dev
2024-09-17 13:06:50 +02:00
parent 95070ab48d
commit 2d8bda4fa6
3 changed files with 28 additions and 23 deletions

View File

@@ -178,4 +178,21 @@ class PrivateKey extends BaseModel
&& $this->githubApps()->count() === 0
&& $this->gitlabApps()->count() === 0;
}
public function isInUse()
{
return $this->servers()->exists()
|| $this->applications()->exists()
|| $this->githubApps()->exists()
|| $this->gitlabApps()->exists();
}
public function safeDelete()
{
if ($this->isInUse()) {
throw new \Exception('This private key is in use and cannot be deleted.');
}
$this->delete();
}
}