Files
alrahma_sunday_school_api/app/Http/Resources/Attendance/TeacherAttendanceFormResource.php
T
2026-04-25 00:00:23 -04:00

32 lines
1.3 KiB
PHP

<?php
namespace App\Http\Resources\Attendance;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class TeacherAttendanceFormResource extends JsonResource
{
public function toArray(Request $request): array
{
$enable = (int)($this['enable_attendance'] ?? 0);
$res = $this->resource;
$hasCanEditKey = is_array($res) && array_key_exists('can_edit', $res);
return [
'teacher_name' => $this['teacher_name'] ?? null,
'students' => $this['students'] ?? [],
'teachers' => $this['teachers'] ?? [],
'class_section_id' => $this['class_section_id'] ?? null,
'sunday_dates' => $this['sunday_dates'] ?? [],
'current_sunday' => $this['current_sunday'] ?? null,
'enable_attendance' => $this['enable_attendance'] ?? null,
// Do not default missing `can_edit` to false — that disables the whole form while attendance is enabled.
'can_edit' => $hasCanEditKey ? (bool) $this['can_edit'] : ($enable === 1),
'class_id' => $this['class_id'] ?? null,
'no_school_days' => $this['no_school_days'] ?? [],
'today' => $this['today'] ?? null,
'locked_by_student' => $this['locked_by_student'] ?? [],
];
}
}