*/ public function toArray(Request $request): array { return [ 'id' => $this->id, 'mobile' => $this->mobile, 'nickname' => $this->nickname, 'avatar' => $this->avatar, 'gender' => $this->gender, 'gender_text' => $this->getGenderText(), 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, // 技师相关信息 'coach' => $this->when($this->coach, function () { return [ 'id' => $this->coach->id, 'state' => $this->coach->state, 'state_text' => $this->coach->state_text, // 如果有申请记录,返回申请状态 'application' => $this->when($this->coach->info, function () { return [ 'id' => $this->coach->info->id, 'state' => $this->coach->info->state, 'state_text' => $this->coach->info->state_text, 'created_at' => $this->coach->info->created_at, ]; }), ]; }), ]; } /** * 获取性别文本 */ private function getGenderText(): string { return match ($this->gender) { 0 => '未知', 1 => '男', 2 => '女', default => '未知', }; } }