Checkbox attendance status how i can set checkbox based present and absent..
i mean how i can work with array of checkbox when i have to work with attendance.
@foreach ($students as $student)
<div>
<input type="checkbox" value="{{ $student->id }}" name="present[]">{{ $student->name }}
</div>
@endforeach
In the controller
$studentsPresent = $request->present;
dd($studentsPresent);// array of student ids that were checked.
The key is the name="present[]" with the [ ] after the name, which means "array".
@Cronix please guide me how to do this in user side..
is there any need of hidden input?
No you don't need hidden input. I showed how to do this, I don't know what you mean by "how to do this on user side". The first code block shows how to generate the checkboxes in the view (I assume this is what you mean by "user side"). The 2nd code block shows how to retrieve them in the controller.
Present
i have this one checkbox ,how can i know different states of 0 and 1
@Cronix
Well the way I showed will only show the ones who are present. From that you should be able to tell which ones weren't?
$studentsPresent = $request->present;
$studentsAbsent = Students::whereNotIn('id', $studentsPresent)->get();
Checkboxes only submit the value if they are checked.
Please sign in or create an account to participate in this conversation.