find(auth()->id()); if (! $user) { return $this->error('用户不存在'); } $data = $user->toArray(); // 手机号脱敏:13812345678 → 138****5678 if (! empty($data['mobile'])) { $data['mobile'] = substr_replace($data['mobile'], '****', 3, 4); } // 邮箱脱敏:test@example.com → t***@example.com if (! empty($data['email'])) { $parts = explode('@', $data['email']); $parts[0] = substr($parts[0], 0, 1).'***'; $data['email'] = implode('@', $parts); } return $this->success($data); } /** 编辑用户信息(头像、昵称、性别) */ #[PutRoute('/profile')] public function updateProfile(Request $request): JsonResponse { $data = $request->validate([ 'avatar' => 'required|string|max:500', 'nickname' => 'required|string|max:32', 'gender' => 'required|integer|in:0,1,2', ]); $user = UserModel::query()->find(auth()->id()); $user->update($data); return $this->success($user->toArray(), '更新成功'); } }