Files
mykopkb-be/Modules/Investment/Transformers/SalaryContributionResource.php

37 lines
1.3 KiB
PHP

<?php
namespace Modules\Investment\Transformers;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class SalaryContributionResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'investment_type_id' => $this->investment_type_id,
'monthly_amount' => $this->monthly_amount,
'start_date' => $this->start_date?->toDateString(),
'end_date' => $this->end_date?->toDateString(),
'status' => $this->status?->value ?? $this->status,
'created_by' => $this->created_by,
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
'user' => $this->whenLoaded('user', fn () => [
'id' => $this->user->id,
'name' => $this->user->name,
'email' => $this->user->email,
'ic_number' => $this->user->ic_number,
]),
'investment_type' => $this->whenLoaded('investmentType', fn () => [
'id' => $this->investmentType->id,
'code' => $this->investmentType->code,
'name' => $this->investmentType->name,
]),
];
}
}