lasthourcloud/app/Livewire/Destination/Form.php

45 lines
1.4 KiB
PHP
Raw Normal View History

2023-05-04 08:45:09 +00:00
<?php
2023-12-07 18:06:32 +00:00
namespace App\Livewire\Destination;
2023-05-04 08:45:09 +00:00
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',
'destination.server.ip' => 'IP Address/Domain',
2023-06-16 10:35:40 +00:00
];
2023-05-04 08:45:09 +00:00
public function submit()
{
$this->validate();
$this->destination->save();
}
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()) {
2023-12-07 18:06:32 +00:00
return $this->dispatch('error', 'You must delete all resources before deleting this destination.');
2023-05-16 09:02:51 +00:00
}
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();
2023-12-27 15:45:01 +00:00
return redirect()->route('dashboard');
2023-09-11 15:36:30 +00:00
} catch (\Throwable $e) {
return handleError($e, $this);
2023-05-16 09:02:51 +00:00
}
2023-05-04 08:45:09 +00:00
}
}