Files
aso/app/Http/Resources/OLDLMS/MemberResource.php

44 lines
1.5 KiB
PHP

<?php
namespace App\Http\Resources\OLDLMS;
use Illuminate\Http\Resources\Json\JsonResource;
class MemberResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
// $data = parent::toArray($request);
$currentMemberPlan = $this->memberPlans?->first();
$data = [
'member_id' => $this->member_id,
'birth_date' => $this->birth_date,
'email' => $this->email,
'phone' => $this->person->phone ?? null,
'full_name' => $this->full_name,
'nric' => $this->nric,
'plan' => $currentMemberPlan ? [
'code' => $currentMemberPlan->plan->code ?? null,
'start' => $currentMemberPlan->start,
'end' => $currentMemberPlan->end
] : null,
'policy_code' => $this->currentPolicy->code,
'corporate' => [
'code' => $this->currentPolicy->corporate->code,
'name' => $this->currentPolicy->corporate->name,
'welcome_message' => $this->currentPolicy->corporate->welcome_message,
'help_text' => $this->currentPolicy->corporate->help_text,
'avatar_url' => $this->currentpolicy->corporate->avatar_url
]
];
return $data;
}
}