如何在控制器Laravel 5中为每个接收增量ID [英] how to receive an incremented id though for each in controller laravel 5

查看:51
本文介绍了如何在控制器Laravel 5中为每个接收增量ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,当我提交时,我现在通过未知大小的foreach增加复选框的id,我想在这里接收所有已发送的数据是我的代码:

i have a form that i increase the id of checkbox through a foreach with unknown size now when i submit i want to receive all of the sent data here is my code :

 <form action="/somecontroller" method="post">
                    <div  id="checkboxes" class="col-lg-2 text-center">
                        <input type="checkbox" name="rGroup" name="d{{$index}}" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>
                        <label class="whatever mt-3" for="d{{$index}}"> {{verta($pdates->date)->format('Y/m/d')}}
                            <hr>
                            {{$pdates->price}}</label>
                    </div>
                    </form>

这是控制器:

 $recived_data = $request->d{{$index}}; here i want to get all the checkboxes send by user

那么我该如何获取用户发送的数据,而我却不知道复选框的数量

so how can i recive the data that user send which i dont know the number of checkboxes

推荐答案

您可以使用input元素的数组语法,并在控制器中接收包含选定项的数组,因此将输入复选框更改为:

You can use array syntax of the input element, and receive the array with selected items in the controller, so change your input checkbox to this:

<input type="checkbox" name="d[{{$index}}]" value="{{verta($pdates->date)->format('Y/m/d')}}" id="d{{$index}}"/>

然后在您的控制器中:

$request->input('d'); // returns an array of indexes of all the selected checkboxes.

这篇关于如何在控制器Laravel 5中为每个接收增量ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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