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',
|
|
|
|
];
|
2023-06-16 10:35:40 +00:00
|
|
|
protected $validationAttributes = [
|
|
|
|
'destination.name' => 'name',
|
|
|
|
'destination.network' => 'network',
|
2023-11-03 09:57:58 +00:00
|
|
|
'destination.server.ip' => 'IP Address/Domain',
|
2023-06-16 10:35:40 +00:00
|
|
|
];
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-04 08:45:09 +00:00
|
|
|
public function submit()
|
|
|
|
{
|
|
|
|
$this->validate();
|
|
|
|
$this->destination->save();
|
|
|
|
}
|
2023-08-08 09:51:36 +00:00
|
|
|
|
2023-05-04 08:45:09 +00:00
|
|
|
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.');
|
|
|
|
}
|
2023-05-24 13:25:08 +00: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 09:02:51 +00:00
|
|
|
}
|
|
|
|
$this->destination->delete();
|
|
|
|
return redirect()->route('dashboard');
|
2023-09-11 15:36:30 +00:00
|
|
|
} catch (\Throwable $e) {
|
2023-09-22 12:47:25 +00:00
|
|
|
return handleError($e, $this);
|
2023-05-16 09:02:51 +00:00
|
|
|
}
|
2023-05-04 08:45:09 +00:00
|
|
|
}
|
|
|
|
}
|