CluPilotCloud/app/Livewire/Admin/ConfirmRemoveHost.php

41 lines
955 B
PHP

<?php
namespace App\Livewire\Admin;
use App\Models\Host;
use LivewireUI\Modal\ModalComponent;
/**
* Confirmation for the destructive "remove host" action (R5). Deregisters the
* CluPilot record only — it does not touch the physical server.
*/
class ConfirmRemoveHost extends ModalComponent
{
public string $uuid;
public string $name = '';
public function mount(string $uuid): void
{
$this->uuid = $uuid;
$this->name = Host::query()->where('uuid', $uuid)->value('name') ?? '';
}
public function remove()
{
$host = Host::query()->where('uuid', $this->uuid)->first();
if ($host !== null) {
$host->runs()->delete(); // cascades run_resources + step_events
$host->delete();
}
return $this->redirectRoute('admin.hosts', navigate: true);
}
public function render()
{
return view('livewire.admin.confirm-remove-host');
}
}