@php
$userMaterial = $auth->userMaterials->where('material_id', $material->id)->first();
$next = null;
if ($material && $material->sub_module) {
$materials = $material->sub_module->materials->sortBy('id');
$currentIndex = $materials->search(function ($m) use ($material) {
return $m->id == $material->id;
});
if ($currentIndex !== false && isset($materials[$currentIndex + 1])) {
$next = $materials[$currentIndex + 1];
}
}
// Handle assignment check
$ass = $material->sub_module->assignments->whereNotIn('id', $auth->userAssignments->pluck('assignment_id'))->first();
$questionCheck = $ass ? DB::table('questions')->where('assignment_id', $ass->id)->exists() : false;
@endphp
@if ($userMaterial && $userMaterial->completed)
Completed
@if ($next)
Go to next item
@elseif ($ass)
@if ($questionCheck)
Go to next item
@else
Go to next item
@endif
@else
Go to next item
@endif
@else
@endif