Guys iam working with a project School Management System.
i have tables like below
Table: ExaminationDetails
id year_id exam_code exam_name
1 1 EX01 QuarterlyExam
2 1 Ex02 Halfyearly Exam
Table: SubjectDetails
id year_id subject_code subject_name
1 1 S01 English
2 1 S02 Maths
Table: MainMark
id year_id class_id section_id exam_id
1 1 1 1 1
2 1 1 1 2
// here i have added a class 1= V std section 1= A section exam id 1=QuarterlyExam
Table: SubMark
id year_id exam_date student_id subject_id mark
1 1 25-01-20 1 1 80
2 1 25-01-20 2 1 90
3 1 25-01-20 3 1 98
4 1 25-01-20 4 1 70
5 1 25-01-20 5 1 60
// Here i have added 5 students of same class V std A section for same subject English marks
Now brought the results based on student id with specific examination everything works fine.
but i expect the result which changes like below
if the user chooses a specific student only then the output must be
Student Name: Abdul Bazith class: V std section:A
Exam english maths physics science social Total
Quarterly 80 70 60 30 20 260
Halfyearly 40 30 60 70 80 280
.
.
.
so on
This gives that student whole marks in a single view
If the user chooses specific student name and specific exam then the output look like
Name: Abdul Bazith Exam: Quarterly Class: Vstd Section:A
Subject marks
english 80
maths 60
chemistry 30
social 20
Total 190
if the user just chooses on the class and section then the output must change like below
Class: V std Section: A
Examination: Quarterly
Student english maths social
abdul 80 30 20
bazith 20 70 60
Examination: Halfyearly
student English maths social
abdul 60 70 80
bazith 70 60 90
/ / this shows all the examination of a single class with all student.
Like above all the details must change based on the user change.
whats my question is do i need to have multiple methods in controller basedon user change or a single method but multiple pages in balde file. or single method and single page is enough but need to have multiple if conditions?
at present my output is like below
my controller is
public function student_marks(Request $request)
{
$classi=SectionDetail::where([
['id', '=', $request->section_id],
['class_id', '=', $request->class_id],
])->first();
$years = AcademicYear::orderBy('created_at', 'desc')->get();
$classes = ClassDetail::orderBy('created_at', 'desc')->get();
$examination = ExaminationInfo::all();
$subjects = SubjectInfo::all();
$examin = ExaminationInfo::find($request->exam_id);
$students = StudentMainMark::where(function ($query) use ($request) {
if (!empty($request->class_id)) {
$query->where('class_id', $request->class_id);
}
if (!empty($request->section_id)) {
$query->where('section_id', $request->section_id);
}
if (!empty($request->exam_id)) {
$query->where('exam_id', $request->exam_id);
}
})->first();
$headers =StudentSubMark::where('main_mark_id', $students->id)->orderBy('subject_id')->distinct('subject_id')->get();
$groups = StudentSubMark::where('main_mark_id', $students->id)->orderBy('subject_id')->get()->groupBy('user.user_name');
return view('StudentMark.manage-students-marks')->withStudents($students)->withYears($years)->withclasses($classes)->withExamination($examination)->withExamin($examin)->withClassi($classi)->withSubjects($subjects)->with($request->all())->withGroups($groups)->withHeaders($headers);
}
and my blade file is like below
<table class="table table-sm table-bordered" id="StudentMarkTable">
<thead>
<tr class="bhg">
<th>S.No</th>
<th>Name</th>
@foreach($headers->unique('subject_id') as $header)
<th>{{ $header->subject->sub_name }}</th>
@endforeach
<th>Total</th>
</tr>
</thead>
<tbody class="capital">
@foreach($groups as $student => $results)
@php
$total = 0;
@endphp
<tr>
<td> {{ $loop->iteration }} </td>
<td>{{$student ?? "wait" }}</td>
@foreach($results as $result)
@if($result->mark==0)
<td> <a href="" data-studid="{{$student}}" data-subid="{{ $result->id }}"
data-subject="{{ $result->subject->sub_name }}" data-mark="{{ $result->mark }}" data-toggle="modal"
data-target="#editstudmark"> <b>A</b> </a></td>
@else
<td> <a href="" data-studid="{{$student}}" data-subid="{{ $result->id }}"
data-subject="{{ $result->subject->sub_name }}" data-mark="{{ $result->mark }}" data-toggle="modal"
data-target="#editstudmark">{{$result->mark ?? 0}}</a></td>
@endif
@php
$total += $result->mark;
@endphp
@endforeach
<td><b>{{$total}}</b></td>
</tr>
@endforeach
</tbody>
</table>
My output screen is : https://imgur.com/NWBtdd0
In my output i need to choose class, section, and exam also if these three are chosen the the output looks like this image.
My models
//Mainmark model
public function studentsubmark()
{
return $this->hasmany('App\StudentSubMark', 'main_mark_id');
}
//submark model
public function studentmainmark()
{
return $this->belongsTo('App\StudentMainMark', 'main_mark_id');
}
public function user()
{
return $this->belongsTo('App\User', 'student_id');
}
public function subject()
{
return $this->belongsTo('App\SubjectInfo', 'subject_id');
}
Kindly some one suggest your ideas please