coolify/app/Http/Livewire/Destination/Form.php

38 lines
1.2 KiB
PHP
Raw Normal View History

2023-05-04 10:45:09 +02:00
<?php
namespace App\Http\Livewire\Destination;
use Livewire\Component;
class Form extends Component
{
2023-05-04 11:14:37 +02:00
public mixed $destination;
2023-05-04 10:45:09 +02:00
protected $rules = [
'destination.name' => 'required',
'destination.network' => 'required',
'destination.server.ip' => 'required',
];
public function submit()
{
$this->validate();
$this->destination->save();
}
public function delete()
{
2023-05-16 11:02:51 +02:00
try {
if ($this->destination->getMorphClass() === 'App\Models\StandaloneDocker') {
if ($this->destination->attachedTo()) {
return $this->emit('error', 'You must delete all resources before deleting this destination.');
}
2023-05-24 15:25:08 +02:00
instant_remote_process(["docker network disconnect {$this->destination->network} coolify-proxy"], $this->destination->server, throwError: false);
instant_remote_process(['docker network rm -f ' . $this->destination->network], $this->destination->server);
2023-05-16 11:02:51 +02:00
}
$this->destination->delete();
return redirect()->route('dashboard');
} catch (\Exception $e) {
2023-06-09 15:55:21 +02:00
return general_error_handler(err: $e);
2023-05-16 11:02:51 +02:00
}
2023-05-04 10:45:09 +02:00
}
}