44 lines
1.4 KiB
PHP
44 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
class SampleResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @param \Illuminate\Http\Request $request
|
|
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
|
|
*/
|
|
public function toArray($request)
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'sample_number' => $this->sample_number,
|
|
'patient' => $this->whenLoaded('patient', function (){
|
|
return [
|
|
'id' => $this->patient->id,
|
|
'uuid' => $this->patient->patient_uuid,
|
|
'name' => $this->patient->name_en
|
|
];
|
|
}),
|
|
'sample_source' => $this->whenLoaded('sample_source',function (){
|
|
return [
|
|
'id' => $this->sample_source->id,
|
|
'name' => $this->sample_source->name_en
|
|
];
|
|
}),
|
|
'physician' => $this->whenLoaded('physician',function (){
|
|
return [
|
|
'id' => $this->physician->id,
|
|
'name' => $this->physician->name_en
|
|
];
|
|
}),
|
|
'sample_details' => $this->whenLoaded('sample_details'),
|
|
'sample_tests' => $this->whenLoaded('sample_tests')
|
|
];
|
|
}
|
|
}
|