Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hsnch41's avatar

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.

0 likes
6 replies
Cronix's avatar
@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".

hsnch41's avatar

@Cronix please guide me how to do this in user side.. is there any need of hidden input?

Cronix's avatar

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.

hsnch41's avatar

Present

i have this one checkbox ,how can i know different states of 0 and 1 @Cronix

Cronix's avatar

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 or to participate in this conversation.