New-Thanasoft/thanasoft-back/app/Http/Resources/Employee/ThanatopractitionerCollection.php
2025-11-05 17:09:12 +03:00

46 lines
2.1 KiB
PHP

<?php
namespace App\Http\Resources\Employee;
use Illuminate\Http\Resources\Json\ResourceCollection;
class ThanatopractitionerCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array<int|string, mixed>
*/
public function toArray($request): array
{
return [
'data' => $this->collection->map(function ($thanatopractitioner) {
return [
'id' => $thanatopractitioner->id,
'employee_id' => $thanatopractitioner->employee_id,
'diploma_number' => $thanatopractitioner->diploma_number,
'diploma_date' => $thanatopractitioner->diploma_date?->format('Y-m-d'),
'authorization_number' => $thanatopractitioner->authorization_number,
'authorization_issue_date' => $thanatopractitioner->authorization_issue_date?->format('Y-m-d'),
'authorization_expiry_date' => $thanatopractitioner->authorization_expiry_date?->format('Y-m-d'),
'notes' => $thanatopractitioner->notes,
'is_authorization_valid' => $thanatopractitioner->is_authorization_valid,
'created_at' => $thanatopractitioner->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $thanatopractitioner->updated_at?->format('Y-m-d H:i:s'),
// Relations
'employee' => $thanatopractitioner->employee ? [
'id' => $thanatopractitioner->employee->id,
'first_name' => $thanatopractitioner->employee->first_name,
'last_name' => $thanatopractitioner->employee->last_name,
'full_name' => $thanatopractitioner->employee->full_name,
'email' => $thanatopractitioner->employee->email,
'job_title' => $thanatopractitioner->employee->job_title,
] : null,
];
}),
];
}
}