$this->id, 'name' => $this->name, 'letter' => $this->letter, 'company_name' => $this->company_name, 'company_position' => $this->company_position, 'company_product' => $this->company_product, 'open_mobile' => (bool) ($this->open_mobile ?? false), 'mobile' => ($this->open_mobile ?? false) ? $this->mobile : null, 'course_signs' => $this->formatCourseSigns(), ]; } protected function formatCourseSigns(): array { if (!$this->relationLoaded('courseSigns')) { return []; } return $this->courseSigns->map(function ($sign) { $course = $sign->course; $typeDetail = $course ? $course->typeDetail : null; return [ 'position' => $sign->position ?? null, 'course' => $course ? [ 'year' => $course->year ?? null, 'name' => $course->name ?? null, 'type_detail' => $typeDetail ? [ 'name' => $typeDetail->name ?? null, ] : null, ] : null, ]; })->values()->all(); } }