2025-11-05 17:09:12 +03:00

38 lines
1.1 KiB
PHP

<?php
namespace App\Http\Resources\Employee;
use Illuminate\Http\Resources\Json\JsonResource;
class EmployeeResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array<string, mixed>
*/
public function toArray($request): array
{
return [
'id' => $this->id,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'full_name' => $this->full_name,
'email' => $this->email,
'phone' => $this->phone,
'job_title' => $this->job_title,
'hire_date' => $this->hire_date?->format('Y-m-d'),
'active' => $this->active,
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
// Relations
'thanatopractitioner' => $this->when(
$this->relationLoaded('thanatopractitioner'),
new ThanatopractitionerResource($this->thanatopractitioner)
),
];
}
}