serverId = $serverId; if ($cred = Server::find($serverId)?->credential) { $this->username = $cred->username; $this->authType = $cred->auth_type; // secret/passphrase are never pre-filled (encrypted at rest) } } public static function modalMaxWidth(): string { return 'lg'; } public function save(): void { $this->error = null; $server = Server::find($this->serverId); if (! $server) { $this->error = 'Server nicht gefunden.'; return; } if (trim($this->username) === '' || trim($this->secret) === '') { $this->error = 'Benutzer und Passwort/Schlüssel sind erforderlich.'; return; } $server->credential()->updateOrCreate([], [ 'username' => trim($this->username), 'auth_type' => $this->authType === 'key' ? 'key' : 'password', 'secret' => $this->secret, 'passphrase' => $this->passphrase !== '' ? $this->passphrase : null, ]); AuditEvent::create([ 'user_id' => Auth::id(), 'server_id' => $server->id, 'actor' => Auth::user()?->name ?? 'system', 'action' => 'server.credential_updated', 'target' => $server->name.' · '.trim($this->username), 'ip' => request()->ip(), ]); $this->dispatch('credentialChanged'); $this->dispatch('notify', message: 'Zugangsdaten gespeichert.'); $this->closeModal(); } public function render() { return view('livewire.modals.edit-credential'); } }