猿问

函数参数太少,1 个已通过,正好 2 个预期 - Laravel

我正在尝试创建一个名为promote()的编辑函数,它编辑userData表中的表值。


这是我使用的表格


<form method="post" action="{{action('PromotionsController@promote', $id )}}">

                       {{csrf_field()}}

                       <input type="hidden" name="_method" value="PATCH" />

                       <input type="text" name="rank" class="'form-control" value="{{$rankid}}" readonly />

                       <input type="text" name="id" class="'form-control" value="{{$id}}" readonly />

                       <input type="submit" class="btn btn-primary" value="Promote" />

                      </form>

值 $rankid 和 $id 已放置在表单中并准备提交。这是控制器的末端。


  /**

     * @param \Illuminate\Http\Request $request

     * @param int $id

     * @return \Illuminate\Http\Response

     */

    public function promote(Request $request, $id)

    {

        $this->validate($request, [

            'rank' => 'required',

            'id' => 'required'

    ]);

      $promotion= userData::find($id);

      $promotion->rank = $request->get('rank');

      $promotion->id = $request->get('id');

        $promotion->save();

      return redirect()->route('home');


    }

我收到错误消息 App\Http\Controllers\PromotionsController::promote() 函数参数太少,已通过 1 个,预期有 2 个,有其他方法可以解决此问题吗?



慕的地8271018
浏览 113回答 1
1回答

至尊宝的传说

尝试这个 :首先创建一条这样的路线route::put('/promote/{id}')->name('promote.update');和<form method="post" action="{{route('promote.update',['id' => $id ])}}">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{csrf_field()}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="hidden" name="_method" value="PUT" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="text" name="rank" class="'form-control" value="{{$rankid}}" readonly />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<input type="submit" class="btn btn-primary" value="Promote" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </form>
随时随地看视频慕课网APP
我要回答