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="
]
《L01 基础入门》
我们将带你从零开发一个项目并部署到线上,本课程教授 Web 开发中专业、实用的技能,如 Git 工作流、Laravel Mix 前端工作流等。
《G01 Go 实战入门》
从零开始带你一步步开发一个 Go 博客项目,让你在最短的时间内学会使用 Go 进行编码。项目结构很大程度上参考了 Laravel。
最佳答案

你的score拼错了 参数和你需要的不一致

4年前 评论
justmd5 4年前
讨论数量: 4

因为你的路由是post动作,应该用$request->post()

4年前 评论

1、先看看HTML里面 value 的值是否正确
2、打印请求内容可以用 $request->all()
3、$request->get() 同样可以获取 post 的数据,实名制反对 1 楼

4年前 评论

@Hanson get it, 学习了

4年前 评论

你的score拼错了 参数和你需要的不一致

4年前 评论
justmd5 4年前

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!