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

45 lines
1.4 KiB
PHP
Raw Normal View History

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',
'destination.server.ip' => 'IP Address',
];
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()) {
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');
} catch (\Exception $e) {
2023-06-09 13:55:21 +00:00
return general_error_handler(err: $e);
2023-05-16 09:02:51 +00:00
}
2023-05-04 08:45:09 +00:00
}
}