@php use App\Models\FamilyMember; use Illuminate\Support\Carbon; use JobMetric\MultiCalendar\Converters\HijriConverter; // Initialize the Hijri converter $hijriConverter = new HijriConverter(); $children = $daleel ->children() ->get() ->map(function ($child) use ($hijriConverter) { // 👉 Step 1: fallback DOB from family_members if (!$child->dob && $child->relation_type == 1) { $familyMember = FamilyMember::select('dob')->where('id', $child->family_tree_id)->first(); if ($familyMember && $familyMember->dob) { $child->dob = $familyMember->dob; // ✅ Detect calendar type using year $parts = preg_split('/[\/\-]/', $child->dob); if (count($parts) === 3) { $year = (int) $parts[2]; // Hijri if year is small (e.g. 1445), Gregorian if large (e.g. 1986) $child->dob_calendar_type = $year < 1700 ? 'hijri' : 'gregorian'; } } } $dob = $child->dob; if (!$dob) { $child->sortable_dob = null; return $child; } // split d/m/Y $parts = preg_split('/[\/\-]/', $dob); if (count($parts) === 3) { [$day, $month, $year] = $parts; if ($child->dob_calendar_type === 'hijri') { [$gYear, $gMonth, $gDay] = $hijriConverter->toGregorian((int) $year, (int) $month, (int) $day); $child->sortable_dob = Carbon::create($gYear, $gMonth, $gDay); } else { $child->sortable_dob = Carbon::createFromFormat('d/m/Y', $dob); } } else { $child->sortable_dob = null; } return $child; }); // Custom sort: first by DOB (oldest first), then by name (Arabic alphabetical) $sortedChildren = $children->sort(function ($a, $b) { $aTimestamp = $a->sortable_dob ? $a->sortable_dob->timestamp : PHP_INT_MAX; $bTimestamp = $b->sortable_dob ? $b->sortable_dob->timestamp : PHP_INT_MAX; // Compare by DOB if ($aTimestamp !== $bTimestamp) { return $aTimestamp <=> $bTimestamp; } // If DOB is equal or missing, compare by name (Arabic) return strcmp($a->name, $b->name); }); @endphp
@if ($daleel->children->count() > 0) @foreach ($sortedChildren as $child) @endforeach @else @endif
@if ($daleel->children->count() > 0) @endif جنس على قيد الحياة الهوية إسم تاريخ الميلاد تاريخ الوفاة
{{ $child->gender == 0 ? 'ذكر' : 'أنثى' }} @php // Check if node exists $aliveStatus = $child->getNodeId?->nodeID ? $child->getNodeId->alive : $child->alive; // Convert to Arabic text $aliveArabic = $aliveStatus == 1 ? 'نعم' : 'لا'; @endphp {{ $aliveArabic }} {{ $child->getNodeId?->nodeID }} {!! $child->get_full_name2() !!} {!! $child->dob !!} {!! $child->dod !!}
لا يوجد محتوى