nimuli/app/Livewire/Modals/DeleteDomain.php

50 lines
1.2 KiB
PHP

<?php
namespace App\Livewire\Modals;
use App\Domains\Domain\Models\Domain;
use Illuminate\View\View;
use LivewireUI\Modal\ModalComponent;
class DeleteDomain extends ModalComponent
{
public int $domainId = 0;
public string $hostname = '';
public function mount(int $domainId): void
{
$workspace = app('current_workspace');
$domain = Domain::where('id', $domainId)
->where('workspace_id', $workspace->id)
->firstOrFail();
$this->domainId = $domainId;
$this->hostname = $domain->hostname;
}
public function delete(): void
{
$workspace = app('current_workspace');
Domain::where('id', $this->domainId)
->where('workspace_id', $workspace->id)
->firstOrFail()
->delete();
$this->dispatch('domainDeleted', domainId: $this->domainId);
$this->dispatch('toast', message: 'Domain gelöscht', type: 'success');
$this->closeModal();
}
public static function modalMaxWidth(): string
{
return 'sm';
}
public function render(): View
{
return view('livewire.modals.delete-domain');
}
}