I'm trying to store attendance of college students on single submit button, a teacher would mark 'present' or 'absent' checkbox, once all checkboxes are selected I want to store the values of these checkboxes as well as the id's of the student in the database. List of students is coming from the database using foreach() function.
So how can I append the student id# with checkbox value so that in the controller I get both, the user Id as well as the 'present' or 'absent' value?
@ershakti thank you, I see some hope in your answer, can you please give a code example of how can I get student id and 'absent', 'present' status in the controller and inserting it in Attendance model.
@foreach ($students as $student)
<ul class="list-group">
<li class="list-group-item"><input type="checkbox" checked value="1" name="stud_id[]">Present</li>
<li class="list-group-item"><input type="checkbox" value="2" name="stud_id[]">Absent</li>
</ul>
//Put Hidden Input here with the $student->id
@endforeach
In your controller:
$count = count($request->student_id);
for($i = 0; $i < $count; ++$i){
if($request->student_id[$i] == null){
//If this student doen't have 1 or 2 checked, do nothing. Not really for your case scenario but I don't see why not leave this as a safeguard.
} else {
//CREATE this student attendance row.
}
}