coolify/app/Livewire/Destination/Form.php

47 lines
1.4 KiB
PHP
Raw Normal View History

2023-05-04 10:45:09 +02:00
<?php
2023-12-07 19:06:32 +01:00
namespace App\Livewire\Destination;
2023-05-04 10:45:09 +02:00
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',
];
2024-06-10 22:43:34 +02:00
2023-06-16 12:35:40 +02:00
protected $validationAttributes = [
'destination.name' => 'name',
'destination.network' => 'network',
'destination.server.ip' => 'IP Address/Domain',
2023-06-16 12:35:40 +02:00
];
2023-05-04 10:45:09 +02:00
public function submit()
{
$this->validate();
$this->destination->save();
}
2023-05-04 10:45:09 +02:00
public function delete()
{
2023-05-16 11:02:51 +02:00
try {
if ($this->destination->getMorphClass() === 'App\Models\StandaloneDocker') {
if ($this->destination->attachedTo()) {
2023-12-07 19:06:32 +01:00
return $this->dispatch('error', 'You must delete all resources before deleting this destination.');
2023-05-16 11:02:51 +02:00
}
2023-05-24 15:25:08 +02:00
instant_remote_process(["docker network disconnect {$this->destination->network} coolify-proxy"], $this->destination->server, throwError: false);
2024-06-10 22:43:34 +02:00
instant_remote_process(['docker network rm -f '.$this->destination->network], $this->destination->server);
2023-05-16 11:02:51 +02:00
}
$this->destination->delete();
2024-06-10 22:43:34 +02:00
2023-12-27 16:45:01 +01:00
return redirect()->route('dashboard');
2023-09-11 17:36:30 +02:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-16 11:02:51 +02:00
}
2023-05-04 10:45:09 +02:00
}
}