【发布时间】:2019-09-26 15:19:06
【问题描述】:
我在一个表中列出了许多行,并且我正在尝试使用每行中存在的下拉菜单来编辑它们。下面的代码很好,但它只会存储最后一个(S_Rank)值(这是我要更改的列),这是获取每一行输入的最佳方式。我知道表单不是数组的问题,将其设为数组的方法是什么
我的看法
{!! Form::open(['action' => 'AbstractsController@UpdateRank' , 'method' => 'post' ]) !!}
<table id="myTable" class ="table table-striped">
<thead>
<td><h4>Student Name</h4></td>
<td><h4>Student Rank</h4></td>
</thead>
@foreach($applications as $application)
<tbody>
<tr>
<td><h5>{{$application->Student_Name}}</h5></td>
<td><h5>
{{Form::select('Ranking' ,$ranks, ['class' => 'form-control', 'placeholder' =>$application->S_Rank] )}}
{{Form::hidden('Student_ids[]', $application->S_ID)}}
</h5></td>
</tr>
@endforeach
</tbody>
</table>
{{Form::Submit('Save New Ranking',['class' => 'btn btn-primary'])}}
{!! Form::close() !!}
我的控制器
foreach(request('Student_ids') as $S_ID){
$application = Application::where('S_ID' , $S_ID)->get();
$application->S_Rank = $request-> input('Ranking');
$application->save();}
我正在尝试使用每个下拉菜单中输入的值更新每一行
【问题讨论】:
-
request('Student_ids')来自哪里? -
ops,隐藏的表单应该是 Student_ids[],编辑正确@khartnett
-
看起来每行都有一个“排名”下拉菜单。您是否希望下拉列表仅更新该行的应用程序?或更新具有该 S_ID 的每个应用程序的排名?现在看起来你正在尝试更新每个 student_id 的每个应用程序排名
-
我希望每个下拉列表都更新该单行(该应用程序)@khartnett
-
最后一个问题。应用程序是否具有唯一 ID?还是 S_ID 是它的唯一 ID?