File: /mnt/data/ghayatcom/ghayatcom-api/app/Http/Resources/BillingCollection.php
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class BillingCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
private $code;
public function __construct($resource, $code = 200)
{
parent::__construct($resource);
$this->code = $code;
}
public function toArray($request)
{
return [
'code' => $this->code,
'message' => [__('digimed_validation.success_response.billing_list_success')],
'data' => [ 'billing' => $this->collection->map(function($item){
/**
* @var object $item
*/
return [
'id' => $item->id,
'consultation_type' => $item->consultation_type,
'clinic_appointment_id' => $item->clinic_appointment_id,
'consultation_type_str' =>$item->consultation_type_str,
'consultation_id' => $item->consultation_id,
'patient_id' => $item->patient_id,
'doctor_id' => $item->doctor_id,
'appointment_status' => $item->appointment_status,
'created_at' => $item->created_at,
'appointment_date' => $item->appointment_start_dt,
// 'appointment_status_str' => ($item->appointment_status == 1 ? "New":($item->appointment_status == 2 ? "Approved":($item->appointment_status == 3 ? "Completed":($item->appointment_status == 4 ? "Cancelled":($item->appointment_status == 5 ? "Expired":($item->appointment_status == 6 ? "Rejected":"")))))),
'payment_details' => (isset($item->paymentDetails)) ? $item->paymentDetails : (object) []
];
})]
];
}
public function withResponse($request, $response)
{
/** @var array $jsonResponse */
$jsonResponse = json_decode($response->getContent(), true);
unset($jsonResponse['links']);
$response->setContent(json_encode($jsonResponse));
}
}