You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.4 KiB
47 lines
1.4 KiB
<?php
|
|
|
|
namespace App\Http\Resources\Mobile;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class UserListResource extends JsonResource
|
|
{
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $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();
|
|
}
|
|
}
|