@php $allLessons = $course->chapters->flatMap->lessons; $doneCount = $allLessons->whereIn('id', $done)->count(); $pct = $allLessons->count() ? (int) round($doneCount / $allLessons->count() * 100) : 0; $currentIdx = $course->chapters->search(fn ($c) => $c->lessons->contains('id', $lesson->id)); @endphp