calculate how many students answered this question with this answer in eloquent
guys iam working with online examination.
the process is staff will create an assessment that will be stored in AssessmentTable.
student can view the assessment and can write the exam.
how i framed the table is
QuestionTable
id Q.no QuestionDescription options correct_answer
AssessmentMain Table
id assmentname duration marks
AssessmentSub Table
id assmnt_id question_id
i have relationship between AssessmentMain(hasMany assessment sub) and AssessmentSub (belongs to assessmentMain)
and having relationship between Questiontable (has Many AssessmentSub) and AssessmentSub (belongs to questionTable)
and my other tables
StudentExamMain
id assessment_id student_id
1 1 1
2 1 2
3 1 3
StudentExamSub
id studentexammain_id question_id student_answer
//just i showed only 1 question 3 students has written the exam
1 1 1 A
2 1 2 B
3 1 3 C
4 1 4 A
5 2 1 B
6 2 2 C
7 2 3 D
8 2 4 A
9 3 1 B
10 3 2 C
11 3 3 D
12 3 4 A
i have relationship between StudentExamMain and StudentExamSub
i have relationship between StudentSub and QuestionTable
now what my client expecting is
all the questions and answers should be displayed in the screen for that specific assessment. say for example if Assessment1 has 50 questions.
after examination for teacher for that assessment all the 50 questions with 4 options will be displayed and the explanation and correct answer will also be displayed.
till this i did
$studentexams=StudentExamMain::with('studentexamsubdetails')->where('assessment_id',1)->first();
in my blade file
@foreach($studentexams->studentexamsubdetails as $question)
{!! $question->questiondetails->ques_desc !!}
{!! $question->questiondetails->option_a !!}
{!! $question->questiondetails->option_b !!}
{!! $question->questiondetails->option_c !!}
{!! $question->questiondetails->option_d !!}
@if($question->student_answer==$question->questiondetails->correct_answer)
then answer is correct_answer
@else
wrong
@endforeach
this gives the all question with correct answer working fine
but my client expecting a simple calculation with students like
for 1st question how many students wrote correct answer and how many student wrote incorrect.
how can i do that??
Some one help please
Please or to participate in this conversation.