'required', 'last_name' => 'required', 'email' => ['required', 'email', $this->emailUniqueRule()], 'phone' => ['required'], 'password' => 'nullable|confirmed|min:6', 'roles' => ['required', Rule::exists('roles', 'id')], ]; } private function emailUniqueRule() { $rule = Rule::unique('users'); if ($this->route()->getName() === 'admin.users.update') { $userId = $this->route()->parameter('id'); return $rule->ignore($userId); } return $rule; } }