Laravel: Get values of checkboxes

Issue

I have multiple checkboxes in the following code:

@foreach($camera_video as $video)
  <input type="checkbox" name="camera_video" value="{{$video->id}}"> <label>{{$video->name}}</label>
@endforeach

I would like to see which checkboxes have been checked by the user. I just need the id (value) to store. What is the best way to do this in Laravel?

Solution

You should update name of your checkbox input to camera_video[] as array and you are good to go. You will get input array.

<input type="checkbox" name="camera_video[]" value="{{$video->id}}"> <label>{{$video->name}}</label>

If you are using Laravel 5.x.x you should use Request object:

public function yourMethod(Request $request)
{
    $cameraVideo = $request->input('camera_video');
    ...
}

Answered By – Buglinjo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published