Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel: Get values of checkboxes

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?

like image 817
hatemjapo Avatar asked Jan 31 '17 20:01

hatemjapo


3 Answers

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');
    ...
}
like image 176
Buglinjo Avatar answered Oct 09 '22 05:10

Buglinjo


You can use

Input::all()

or

Input::get('camera_video')
like image 2
Ahmed Bebars Avatar answered Oct 09 '22 06:10

Ahmed Bebars


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>
like image 1
Imran Avatar answered Oct 09 '22 05:10

Imran