2023-05-04 08:45:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Livewire\Destination;
|
|
|
|
|
|
|
|
use Livewire\Component;
|
|
|
|
|
|
|
|
class Form extends Component
|
|
|
|
{
|
2023-05-04 09:14:37 +00:00
|
|
|
public mixed $destination;
|
2023-05-04 08:45:09 +00: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 09:02:51 +00: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.');
|
|
|
|
}
|
|
|
|
instantRemoteProcess(["docker network disconnect {$this->destination->network} coolify-proxy"], $this->destination->server, throwError: false);
|
|
|
|
instantRemoteProcess(['docker network rm -f ' . $this->destination->network], $this->destination->server);
|
|
|
|
}
|
|
|
|
$this->destination->delete();
|
|
|
|
return redirect()->route('dashboard');
|
|
|
|
} catch (\Exception $e) {
|
2023-05-24 12:26:50 +00:00
|
|
|
return general_error_handler($e);
|
2023-05-16 09:02:51 +00:00
|
|
|
}
|
2023-05-04 08:45:09 +00:00
|
|
|
}
|
|
|
|
}
|