Files
aso/Modules/Linksehat/Transformers/Person/PersonResource.php
2022-11-15 10:43:30 +07:00

47 lines
1.7 KiB
PHP
Executable File

<?php
namespace Modules\Linksehat\Transformers\Person;
use App\Helpers\Helper;
use Illuminate\Http\Resources\Json\JsonResource;
class PersonResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name_prefix' => $this->name_prefix,
'name' => $this->name,
'name_suffix' => $this->name_suffix,
'full_name' => $this->full_name,
'birth_place' => $this->birth_place,
'birth_date' => $this->birth_date,
'gender' => !empty($this->gender) ? ($this->gender == 'M' ? 'P' : 'W') : null, // For App
'citizenship' => $this->citizenship,
'phone' => $this->phone,
'email' => $this->email,
'blood_type' => $this->blood_type,
'weight' => (float) $this->last_weight_kg,
'height' => (float) $this->last_height_cm,
'relation_with_owner' => ($this->user && $this->user->person_id == $this->id) ? 'Self' : $this->pivot->relation_with_owner ?? null,
'marital_status' => $this->marital_status,
'last_education' => $this->last_education,
'current_employment' => $this->current_employment,
'nik' => $this->nik,
'religion' => $this->religion,
'is_deceased' => $this->is_deceased == 1,
'deceased_at' => $this->deceased_at,
'avatar_url' => $this->avatar->url ?? asset('images/default-doctor-avatar.png'),
'main_address' => $this->current_address,
'domicile_address' => $this->domicile_address,
];
}
}