从laravel中的数组文本框中获取值

时间:2017-10-25 08:37:23

标签: php laravel laravel-5

我希望通过点击提交获取foreach中的model_id []值,但我从model_id []获取所有内容。

以我的形式:

<form id="modify" class="form-horizontal" method="POST" action="{{ route('modifymodel') }}"
      onsubmit="return confirm('Are you sure to do this?');">
    {!! csrf_field() !!}
    <table class="table-hover" width="100%" cellpadding="5" cellspacing="0">
        @foreach($data_model as $key=> $va)
            <tr>
                <td width="30px">{{++$key}}</td>
                <td width="280px">
                    <input type="hidden" id="model_id[]" name="model_id[]" value=" {{ $va->model_id }} ">
                    <input type="text" name="txt_depmo" id="txt_depmo" style="width: 280px;"
                           value="{{$va->model_name}}">
                </td>
                <td>
                    <input type="submit" class="btn btn-outline-primary" name="submit" id="submit" value="Updates">
                    <input type="submit" class="btn btn-outline-danger" name="submit" id="submit" value="Removes">
                </td>
            </tr>
        @endforeach
    </table>
</form>

我的控制器:

public function modifymodel(Request $request){
   $modelidd=Input::get('model_id');
 }

但是我在model_id []中获得了所有数组的结果。

["1","3","8","9"]

我想通过点击按钮获取ID

1 个答案:

答案 0 :(得分:1)

在循环中创建表单。我将为每个项目制作表格。

        @foreach($data_model as $key=> $va)

         <form id="modify" class="form-horizontal" method="POST" action="{{ route('modifymodel') }}"
             onsubmit="return confirm('Are you sure to do this?');">
             {!! csrf_field() !!}
            <table class="table-hover" width="100%" cellpadding="5" cellspacing="0">
            <tr>
                <td width="30px">{{++$key}}</td>
                <td width="280px">
                    <input type="hidden" id="model_id[]" name="model_id[]" value=" {{ $va->model_id }} ">
                    <input type="text" name="txt_depmo" id="txt_depmo" style="width: 280px;"
                           value="{{$va->model_name}}">
                </td>
                <td>
                    <input type="submit" class="btn btn-outline-primary" name="submit" id="submit" value="Updates">
                    <input type="submit" class="btn btn-outline-danger" name="submit" id="submit" value="Removes">
                </td>
            </tr>
          </table>
         </form>

        @endforeach