同时提交多个记录-Laravel 5.2


Submitting more than one record at once - 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'AccountController@markStudent', $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>

首先将Form::open移出所有前臂。

然后,您必须更改数组的所有输入(使用$i提交),所以您的循环看起来像:

{!! Form::open(['action' => 'Educator'AccountController@markStudent', $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() !!}

在tbody标记之后将您的{{Form::open}}移动到foreach外部。它应该起作用。