2016-04-30 68 views
0

我在每一行都有一个输入字段的表,但我希望一次提交所有输入,而不是一个接一个。我应该在哪里提交提交按钮?就像那样,我只提交表格中的最后一行。一次提交多条记录 - Laravel 5.2

<table class="table table-responsive table-striped" id="admin-table"> 
    <thead> 
    <tr> 
     <th>Клас:</th> 
     <th>N:</th> 
     <th>Име:</th> 
     <th>Предмет:</th> 
     <th>Оценка:</th> 
     <th>Тип на оценката:</th> 

    </tr> 
    </thead> 
    <tbody> 
    @foreach($students as $student) 
     @foreach($class as $classes) 
      @foreach($sub as $subject) 
     <tr> 
      {!! Form::open(['action' => 'Educator\[email protected]', $subject, 'class' => 'form-horizontal']) !!} 
      <td> 
       {{$classes->name}} 
      </td> 
      <td> 
       {!! Form::text('student_id', $student->id) !!} 
      </td> 
      <td> 
       {{$student->full_name}} 
      </td> 
      <td> 
       {!! Form::text('subject_id', $subject->id) !!} 
      </td> 
      <td> 
       {!! Form::text('mark',null, ['class'=>'form-control col-md-2']) !!} 
      </td> 
      <td> 
       {!! Form::select('markType', $markType, null, ['class'=>'form-control']) !!} 
      </td> 
     </tr> 

      @endforeach 
      @endforeach 
     @endforeach 
    <div align="center"> 
     <a href="{{url('educator/class-subject')}}"><button type="button" class="btn btn-default">Назад</button></a> 
     {!! Form::submit('Запиши', ['class' => 'btn btn-default']) !!} 

    </div> 
    {!! Form::close() !!} 
    </tbody> 
</table> 

回答

2

首先所有的移动Form::open以外的所有foreaches。

,那么你必须改变阵列中所有你输入(与$i itteration),所以你的循环会看起来像:

{!! Form::open(['action' => 'Educator\[email protected]', $subject, 'class' => 'form-horizontal']) !!} 
<table class="table table-responsive table-striped" id="admin-table"> 
    <thead> 
     <tr> 
      <th>Клас:</th> 
      <th>N:</th> 
      <th>Име:</th> 
      <th>Предмет:</th> 
      <th>Оценка:</th> 
      <th>Тип на оценката:</th> 
     </tr> 
    </thead> 
    <tbody> 
    <?php $i = 0; ?> 
    @foreach($students as $student) 
     @foreach($class as $classes) 
      @foreach($sub as $subject) 
       <td> 
        {{$classes->name}} 
       </td> 
       <td> 
        {!! Form::text('entry[][student_id]', $student->id) !!} 
       </td> 
       <td> 
        {{$student->full_name}} 
       </td> 
       <td> 
        {!! Form::text('entry[][subject_id]', $subject->id) !!} 
       </td> 
       <td> 
        {!! Form::text('entry[][mark]',null, ['class'=>'form-control col-md-2']) !!} 
       </td> 
       <td> 
        {!! Form::select('entry[][markType]', $markType, null, ['class'=>'form-control']) !!} 
       </td> 
      <?php $i++; ?> 
      @endforeach 
     @endforeach 
    @endforeach 
    </tbody> 
</table> 
<div align="center"> 
    <a href="{{url('educator/class-subject')}}"><button type="button" class="btn btn-default">Назад</button></a> 
    {!! Form::submit('Запиши', ['class' => 'btn btn-default']) !!} 

</div> 
{!! Form::close() !!} 
+0

不工作..现在我没有从输入字段得到的信息.. –

+0

我reedit我的帖子 –

+0

是的,有一点变化,在它的控制器工作!谢谢! :) –

0

将您的{{Form :: open}}移到tbody标签后面的foreach外部。它应该工作。

+0

不幸的是,没有。 –

+0

菲利普的答案上面修复它:) –