This commit is contained in:
Andras Bacsai 2023-06-15 15:15:27 +02:00
parent b68aabb2c9
commit c9c56c915c
4 changed files with 22 additions and 2 deletions

View File

@ -51,6 +51,10 @@ class Form extends Component
}
public function delete()
{
if (!$this->server->isEmpty()) {
$this->emit('error', 'Server has defined resources. Please delete them first.');
return;
}
$this->server->delete();
redirect()->route('dashboard');
}

View File

@ -14,6 +14,9 @@ class Server extends BaseModel
'server_id' => $server->id,
]);
});
static::deleting(function ($server) {
$server->settings()->delete();
});
}
protected $fillable = [
'name',
@ -33,6 +36,19 @@ class Server extends BaseModel
{
return $this->extra_attributes->modelScope();
}
public function isEmpty()
{
if ($this->applications()->count() === 0) {
return true;
}
return false;
}
public function applications()
{
return $this->destinations()->map(function ($standaloneDocker) {
return $standaloneDocker->applications;
})->flatten();
}
public function destinations()
{
$standalone_docker = $this->hasMany(StandaloneDocker::class)->get();

View File

@ -6,7 +6,7 @@
<x-forms.button wire:click.prevent='submit' type="submit">
Save
</x-forms.button>
@if ($destination->network !== 'coolify')
@if ($destination->server->id === 0 && $destination->network !== 'coolify')
<x-forms.button x-on:click.prevent="deleteDestination = true">
Delete
</x-forms.button>

View File

@ -4,7 +4,7 @@
<div class="flex gap-2">
<h2>General</h2>
<x-forms.button type="submit">Save</x-forms.button>
@if ($server->id !== 0)
@if ($server->id !== 0 || config('app.env') === 'local')
<x-forms.button x-on:click.prevent="deleteServer = true">
Delete
</x-forms.button>