SocialAccount::orderBy('username')->get(), 'networks' => SocialAccount::NETWORKS, 'types' => SocialAccount::TYPES, ]); } public function create(): void { $this->resetForm(); $this->showForm = true; } public function edit(int $id): void { $account = SocialAccount::findOrFail($id); $this->editingId = $account->id; $this->network = $account->network; $this->username = $account->username; $this->email = $account->email; $this->password = $account->password; $this->type = $account->type; $this->showForm = true; } public function save(): void { $validated = $this->validate([ 'network' => ['required', 'string', 'in:' . implode(',', SocialAccount::NETWORKS)], 'username' => ['required', 'string', 'max:255'], 'email' => ['required', 'string', 'max:255'], 'password' => ['required', 'string', 'max:255'], 'type' => ['nullable', 'string', 'in:' . implode(',', SocialAccount::TYPES)], ]); SocialAccount::updateOrCreate(['id' => $this->editingId], $validated); $this->resetForm(); $this->showForm = false; } public function delete(int $id): void { SocialAccount::findOrFail($id)->delete(); } public function toggleReveal(int $id): void { $this->revealedId = $this->revealedId === $id ? null : $id; } public function resetForm(): void { $this->editingId = null; $this->network = ''; $this->username = ''; $this->email = ''; $this->password = ''; $this->type = null; $this->resetValidation(); } }