namespace App\Livewire; use Livewire\Component; use App\Models\Tenant; class TenantManager extends Component { public $tenants, $name, $domain, $editingId; public function mount() { $this->loadTenants(); } public function loadTenants() { $this->tenants = Tenant::all(); } public function save() { $this->validate(['name' => 'required', 'domain' => 'required']); Tenant::updateOrCreate(['id' => $this->editingId], [ 'name' => $this->name, 'domain' => $this->domain, ]); $this->resetInput(); $this->loadTenants(); } public function edit($id) { $tenant = Tenant::find($id); $this->editingId = $tenant->id; $this->name = $tenant->name; $this->domain = $tenant->domain; } public function delete($id) { Tenant::find($id)->delete(); $this->loadTenants(); } public function resetInput() { $this->name = $this->domain = ''; $this->editingId = null; } public function render() { return view('livewire.tenant-manager'); } }