Laravel缺少路线所需的参数:

时间:2018-08-01 21:23:21

标签: laravel laravel-5

我们遇到了一个奇怪的错误,我查看了我们的Git历史记录,几个月来没有人碰过这个控制器和属于它们的路由。

我们有一个表单,该表单从页面中获取GET Request数据并将其从步骤1传递到步骤2。因此,变量被插入到URL中,例如/refer/step_2?name='john'&phone="9999999999"

错误:

Missing required parameters for [Route: step_2] [URI: refer/step/2].

第2步(发布请求):

/**
 * Validates data from step and moves on to step 2.
 *
 * @param Request $request
 */
public function step1_request(Request $request) {
    // Remove any additional characters from the lead phone number.
    $request['phone'] = preg_replace('/\D+/', '', $request->phone);
    $request->merge(['phone' => $request['phone']]);

    $validate = [
        'name' => 'required',
        'phone' => 'required|digits:10'
    ];

    $validationErrorMessages = [
        'phone.digits' => 'The phone number must be 10 digits. No spacing, dashes, or special characters.'
    ];

    $validateData = $request->validate($validate, $validationErrorMessages);

    //dd returns fine here.. includes the request data.
    return redirect()->route('step_2', $request); // <- Error happens here. Missing required parameters for [Route: step_2] 
}

第2步(刀片)

/**
 * Returns a view to confirm the output from step 1.
 *
 * @param Request $request
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function step_2(Request $request) {
    .....
}

路线:

Route::prefix('refer')->group(function () {
    // Step 1
    Route::get('/', ['uses' => 'ReferController@step_1', 'as' => 'step_1']);
    Route::post('/', ['uses' => 'ReferController@step1_request']);
    // Step 2
    Route::get('step/2', ['uses' => 'ReferController@step_2', 'as' => 'step_2']);
    Route::post('/step/2', ['uses' => 'ReferController@step2_request']);
    // Step 3 
    Route::get('step/3', ['uses' => 'ReferController@step3', 'as' => 'step_3']);
    Route::post('step/3', ['uses' => 'ReferController@step3_request']);
});

只需重申一下-这项工作已经进行了几个月,没有任何问题。我已经清除了一个空白数据库,并将git head重置为我们创建该数据库时的初始提交,但仍然遇到相同的错误。是否有Laravel等更新的内容?

1 个答案:

答案 0 :(得分:1)

此问题已通过更改来解决: return redirect()->route('step_2', $request)

至: return redirect()->route('step_2', $request->all())

这似乎是一个应用程序,从最近的一个小补丁中破解了Laravel 5.6中的错误。