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?
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');
...
}
You can use
Input::all()
or
Input::get('camera_video')
You just need to define the name as an array so that you can fetch the input as array in Laravel. Like this:
<input type="checkbox" name="camera_video[]" value="{{$video->id}}"> <label>{{$video->name}}</label>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With