> */ protected function rules(): array { return [ 'name' => ['required', 'string', 'max:120'], 'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users', 'email')], ]; } /** * @return array */ protected function validationAttributes(): array { return [ 'name' => __('accounts.name_label'), 'email' => __('accounts.email_label'), ]; } public function save(): void { $data = $this->validate(); // Re-check uniqueness server-side regardless of the live validator state. $email = mb_strtolower(trim($data['email'])); if (User::where('email', $email)->exists()) { $this->addError('email', __('validation.unique', ['attribute' => __('accounts.email_label')])); return; } $temp = Str::password(16); $user = User::create([ 'name' => trim($data['name']), 'email' => $email, 'password' => Hash::make($temp), 'must_change_password' => true, ]); AuditEvent::create([ 'user_id' => Auth::id(), 'actor' => Auth::user()?->name ?? 'system', 'action' => 'user.create', 'target' => $user->email, 'ip' => request()->ip(), ]); // Reveal the temp password ONCE — swaps the form for the reveal panel. $this->createdName = $user->name; $this->tempPassword = $temp; } /** "Fertig": reload the list and close. */ public function finish(): void { $this->dispatch('usersChanged'); $this->closeModal(); } public function render() { return view('livewire.modals.create-user'); } }