@php $subjects = $student->subject()->orderBy('id','DESC')->limit(1)->get(); $questionIds = \App\OnlineExam\StudentQuestion::where('student_id',$student->id)->select('subject_question_id'); $objectiveQuestions = \App\OnlineExam\SubjectQuestion::whereIn('id',$questionIds)->where('type','Objective'); @endphp @foreach($subjects as $key=>$subject) @if(count($objectiveQuestions->where('subject_id',$subject->id)->get())>0) View Result @php $marks = 0; @endphp @foreach($objectiveQuestions->where('subject_id',$subject->id)->get() as $key=>$objectiveQuestion) @if($checkStudentAnswer = $objectiveQuestion->studentObjectiveAnswers()->where('student_id',$student->id)->first()) @php $questionOption = \App\OnlineExam\QuestionOption::findOrFail($checkStudentAnswer->question_option_id); @endphp @if($questionOption->type=='True') @php $marks += $objectiveQuestion->marks; @endphp @endif @endif @endforeach Total Mask : {{$marks}} {{-- Total Mask : {{$marks}} | {{round(($marks*100)/$objectiveQuestions->sum('marks'),2)}}%--}} @else Not Found @endif @endforeach