Laravel:获取复选框的值 [英] Laravel: Get values of checkboxes

查看:409
本文介绍了Laravel:获取复选框的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下代码中有多个复选框:

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

我想查看用户已经选中了哪些复选框.我只需要存储ID(值)即可.在Laravel中执行此操作的最佳方法是什么?

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?

推荐答案

您应该将复选框输入的名称更新为数组形式的camera_video[],这样您就可以进行了.您将获得输入数组.

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>

如果您使用的是Laravel 5.x.x,则应使用Request对象:

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

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

这篇关于Laravel:获取复选框的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆