2026-05-11 13:30:24 +03:00

50 lines
1.9 KiB
PHP

<?php
namespace App\Http\Resources\Employee;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class LeaveResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'employee_id' => $this->employee_id,
'type' => $this->type,
'status' => $this->status,
'start_date' => $this->start_date?->format('Y-m-d'),
'end_date' => $this->end_date?->format('Y-m-d'),
'reason' => $this->reason,
'notes' => $this->notes,
'approved_by' => $this->approved_by,
'approved_at' => $this->approved_at?->format('Y-m-d H:i:s'),
'created_at' => $this->created_at?->format('Y-m-d H:i:s'),
'updated_at' => $this->updated_at?->format('Y-m-d H:i:s'),
'employee' => $this->when(
$this->relationLoaded('employee') && $this->employee,
fn () => [
'id' => $this->employee->id,
'first_name' => $this->employee->first_name,
'last_name' => $this->employee->last_name,
'full_name' => $this->employee->full_name,
'email' => $this->employee->email,
'job_title' => $this->employee->job_title,
]
),
'approver' => $this->when(
$this->relationLoaded('approver') && $this->approver,
fn () => [
'id' => $this->approver->id,
'name' => $this->approver->name,
'email' => $this->approver->email,
]
),
'histories' => $this->when(
$this->relationLoaded('histories'),
fn () => LeaveHistoryResource::collection($this->histories)
),
];
}
}