问题
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?
回答1:
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');
...
}
回答2:
You can use
Input::all()
or
Input::get('camera_video')
回答3:
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>
来源:https://stackoverflow.com/questions/41966620/laravel-get-values-of-checkboxes