Laravel5.4 为什么使用 request 的 get 方法获取不到 request 中已存在的数据?
我在 dd ($request) 的结果中找到了我要的数据,但是 $request->get () 的结果总是空,这是什么原因呢?
相关部分的代码:
route:
Route::post('perform/edit_pscores/{perform_id}','PbLog\PerformController@editPscores');
表单:
<form action=" {{url("perform/edit_pscores/".$perform->id)}} " method="POST">
{!! csrf_field() !!}
<table width="100%" font-size: 20px; class="table table-striped table-bordered table-hover" id="datatable_week_report">
<thead>
<tr>
<th style="text-align:center">项目名称</th>
<th style="text-align:center">完成分</th>
</tr>
</thead>
<tbody>
@foreach($perform->pscores as $id => $pscore)
<tr>
<td>{{$pscore['name']}}</td>
<td><input name = "{{'psocre_'.$id}}" id = "{{'psocre_'.$id}}" value = "{{$pscore['score']}}"/></td>
</tr>
@endforeach
</tbody>
</table>
<div align = "center">
<button class="btn btn-info radius" type="submit">
<i class="{{trans('common.button_save_icon')}}">{{trans('common.button_save')}}</i>
</button> {{--保存--}}
</div>
</form>
controller:
public function editPscores(Request $request, $perform_id) {
$perform = Perform::findOrFail($perform_id);
$pscores = json_decode($perform->pscores, true);
//$content = explode("&", $request->getContent());
//dd($content);
foreach ($pscores as $project_id => $value) {
$pscores[$project_id]['score'] = $request->get('pscore_' . $project_id);
}
$perform->update(['pscores' => json_encode($pscores)]);
return redirect()->to('perform/'.$perform->year.'/'.$perform->term);
}
controller 中注释部分的执行结果:
array:46 [▼
0 => "_token=bY52eTsexHzpOGCxvjTEb3hhEsAfD7SXl06owLLP"
1 => "psocre_1=1"
2 => "psocre_2="
3 => "psocre_9="
4 => "psocre_10="
5 => "psocre_11="
6 => "psocre_12="
7 => "psocre_13="
8 => "psocre_14="
9 => "psocre_15="
10 => "psocre_16="
11 => "psocre_17="
12 => "psocre_18="
13 => "psocre_19="
14 => "psocre_20="
15 => "psocre_21="
16 => "psocre_23="
17 => "psocre_24="
18 => "psocre_25="
19 => "psocre_26="
20 => "psocre_27="
21 => "psocre_28="
22 => "psocre_29="
23 => "psocre_30="
24 => "psocre_31="
25 => "psocre_32="
26 => "psocre_34="
27 => "psocre_35="
28 => "psocre_36="
29 => "psocre_37="
30 => "psocre_38="
31 => "psocre_39="
32 => "psocre_40="
33 => "psocre_41="
34 => "psocre_42="
35 => "psocre_44="
36 => "psocre_46="
37 => "psocre_47="
38 => "psocre_48="
39 => "psocre_49="
40 => "psocre_50="
41 => "psocre_51="
42 => "psocre_52="
43 => "psocre_53="
44 => "psocre_54="
45 => "psocre_55="
]
推荐文章: