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

shahr's avatar
Level 10

How to save checkbox with array checkbox?

I have a checkbox with name of currently_studying. But I did not successfully.

foreach ($request->field as $key => $value) {
    $educational = new Educational;
    $educational->user_id = auth()->id();
    $educational->grade_id = $request->grade_id[$key];
    $educational->field = $request->field[$key];
    $educational->institution_id = $request->institution_id[$key];
    $educational->branch = $request->branch[$key];
    $educational->institution_education = $request->institution_education[$key];
    $educational->gpa = $request->gpa[$key];
    $educational->country_id = $request->country_id[$key];
    $educational->state_id = $request->state_id[$key];
    $educational->city_id = $request->city_id[$key];
    $educational->state_name = $request->state_name[$key];
    $educational->city_name = $request->city_name[$key];
    $educational->entrance = $request->entrance[$key];
    $educational->graduate = $request->graduate[$key];
    $educational->currently_studying = $request->has('currently_studying')[$key];
    $educational->save();
}
0 likes
5 replies
tykus's avatar

Why is it an "array checkbox" exactly? And what is $request->field?

Snapey's avatar
Snapey
Best Answer
Level 122
$educational->currently_studying = $request->has("currently_studying.$key");
1 like
shahr's avatar
Level 10

@tykus

The $request->field is textbox name

The array checkbox Array. Because I have a form like this

dd

A user add can one or more.

If you have a better solution, code in this post.

Snapey's avatar

so pleased I chose Livewire and gave up trying to juggle this javascript mess.

Please or to participate in this conversation.