Files
aso/Modules/Internal/Transformers/AppointmentResource.php
2023-02-10 16:55:24 +07:00

46 lines
1.8 KiB
PHP

<?php
namespace Modules\Internal\Transformers;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
class AppointmentResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$appointment = [
'id' => $this->nID,
'doctor_name' => isset($this->doctor->user->sFirstName) ? $this->doctor->user->sFirstName . ' ' . $this->doctor->user->sLastName : null,
'speciality' => $this->doctor->speciality->sKeterangan,
'date_appointment' => Carbon::parse($this->appointmentDetail->dTanggalAppointment)->format('d-m-Y') . ' ' . $this->appointmentDetail->tTimeAppointment,
'date_created' => Carbon::parse($this->dCreateOn)->format('d-m-Y H:i:s') ?? null,
'appointment_media' => $this->sMedia,
'status' => $this->status_name,
'health_care' => $this->healthCare->sHealthCare ?? null,
'payment_method' => $this->payment_method ?? null,
];
$payment_detail = null;
if ($this->appointmentDetail->sPaymentDetails != null) {
$payment_detail = [
'payment_type' => $this->appointmentDetail->sPaymentDetails['payment_type'],
'transaction_time' => $this->appointmentDetail->sPaymentDetails['transaction_time'],
'gross_amount' => $this->appointmentDetail->sPaymentDetails['gross_amount'],
'currency' => $this->appointmentDetail->sPaymentDetails['currency'],
'status_message' => $this->appointmentDetail->sPaymentDetails['status_message'],
];
}
$appointment['payment_detail'] = $payment_detail;
return $appointment;
}
}