2017-10-25 7 views
0

私はmodel_id []の値をforeachで取得するには、submitをクリックしますが、model_id []からすべて取得します。私のフォームでlaravelの配列のテキストボックスから値を取得

<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"] 

私は、ループ内でフォームを作成し

+0

'model_id []'は配列なので、配列を返します。あなたの 'foreach'では、すべての項目に対して新しい'

'を開き、入力の名前を' name = "model_id" 'に変更することができます。 – kerbholz

+0

@kerbholzだからforeachで私のフォームを変更する必要がありますか? –

+0

基本的には、コードの最上部に '@ foreach'行を、コードの最後に' @endforeach'行を入れてください。 – kerbholz

答えて

1

をクリックして、私のボタンからIDを取得したいです。私はすべてのアイテムのためのフォームを作成します。

 @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 
+0

しかし、私は何もしないでください。 –

+0

更新された答えを見てください。 –

+0

私はテーブルの中にテーブルを置くとうまくいくよ –

関連する問題