user(); $data = $request->validate([ 'nickname' => ['nullable', 'string', 'max:64'], 'avatar_url' => ['nullable', 'string', 'max:512'], 'name' => ['required', 'string', 'max:64'], 'mobile' => ['required', 'string', 'max:32', 'regex:/^1[3-9]\d{9}$/'], 'company' => ['nullable', 'string', 'max:255'], 'job_title' => ['nullable', 'string', 'max:128'], 'research_direction_ids' => ['nullable', 'array'], 'research_direction_ids.*' => ['integer', 'distinct', Rule::exists('research_directions', 'id')->where('status', 1)], ]); $directionIds = $data['research_direction_ids'] ?? null; unset($data['research_direction_ids']); DB::transaction(function () use ($user, $data, $directionIds) { $user->fill(array_filter($data, fn ($v) => $v !== null)); $user->save(); if (is_array($directionIds)) { $user->researchDirections()->sync($directionIds); } }); return $this->ok(MiniappPresenter::userPayload($user->fresh()), '资料已保存'); } }