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

Heimdall's avatar

checkbox insert

Hello,

I have form, with checkbox, but i want register all case checked but idk how..

My code html:

  				@foreach($categorylist as $categorylist)
  					<input type="radio"  name="categorybox[]"  value="{{$categorylist->id}}" class="checkbox">	{{$categorylist->name}}		
  				@endforeach

and my controller

	     $category_dish = new category_dish();
	     $category_dish->category_id = request("categorybox");
	     $category_dish->dish_id = $Dishs->id;
	     $category_dish->save();

Ty

0 likes
2 replies
Nakov's avatar
Nakov
Best Answer
Level 73

@heimdall what type of field is your category_id? If it is an integer, you might need to loop through the array and persist a row for each of the categories:

foreach(request("categorybox") as $category_id)
{
    $category_dish = new category_dish();
    $category_dish->category_id = $category_id;
    $category_dish->dish_id = $Dishs->id;
    $category_dish->save();
}

And I would guess that you are validating that at least one checkbox is selected, otherwise nothing will be saved here.

Please or to participate in this conversation.