56 lines
2.2 KiB
PHP
56 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources\Intervention;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\JsonResource;
|
|
use App\Http\Resources\Deceased\DeceasedResource;
|
|
use App\Http\Resources\Client\ClientResource;
|
|
use App\Http\Resources\Employee\ThanatopractitionerResource;
|
|
|
|
class InterventionResource extends JsonResource
|
|
{
|
|
/**
|
|
* Transform the resource into an array.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'client' => $this->whenLoaded('client', function () {
|
|
return new ClientResource($this->client);
|
|
}),
|
|
'deceased' => $this->whenLoaded('deceased', function () {
|
|
return new DeceasedResource($this->deceased);
|
|
}),
|
|
'order_giver' => $this->order_giver,
|
|
'location' => $this->whenLoaded('location', function () {
|
|
return [
|
|
'id' => $this->location->id,
|
|
'name' => $this->location->name
|
|
];
|
|
}),
|
|
'type' => $this->type,
|
|
'scheduled_at' => $this->scheduled_at ? $this->scheduled_at->format('Y-m-d H:i:s') : null,
|
|
'duration_min' => $this->duration_min,
|
|
'status' => $this->status,
|
|
'assigned_practitioner' => $this->whenLoaded('assignedPractitioner', function () {
|
|
return new ThanatopractitionerResource($this->assignedPractitioner);
|
|
}),
|
|
'attachments_count' => $this->attachments_count,
|
|
'notes' => $this->notes,
|
|
'created_by' => $this->created_by,
|
|
'created_at' => $this->created_at->format('Y-m-d H:i:s'),
|
|
'updated_at' => $this->updated_at->format('Y-m-d H:i:s'),
|
|
'attachments' => $this->whenLoaded('attachments', function () {
|
|
return InterventionAttachmentResource::collection($this->attachments);
|
|
}),
|
|
'notifications' => $this->whenLoaded('notifications', function () {
|
|
return InterventionNotificationResource::collection($this->notifications);
|
|
})
|
|
];
|
|
}
|
|
}
|