缺少使用返回重定向传递到路由的参数 - Laravel


Missing parameters that are passed to route using return redirect - Laravel

请确认以下步骤是否正确(特别是返回重定向()部分)

路由"仪表板 2"需要 2 个变量,如下所示,以通过 getDashboard 函数打开仪表板视图:

Route::get('/dashboard2/{wordsRowB}/{wordsRowId}', [    
    'uses' => 'DashController@getDashboard',
    'as' => 'dashboard2',
    'middleware' => 'auth'
]);

所以我将这两个变量传递给它,如下所示:

查看代码 :

<a href="{{ route('post.pin', [                    
                          'wordsRowId' => $wordsRowId,
                          'wordsRowB' => $wordsRowB
                         ]) }}">Test</a> 

控制器代码 :

public function postPin($wordsRowId,$wordsRowB)
    {
      return redirect()->route('dashboard2')
      ->with(['wordsRowId' => $wordsRowId])
      ->with(['wordsRowB' => $wordsRowB]);

收到此错误:(您会在错误中找到另外 2 个变量,为了清楚起见,我从上面的代码中删除了这些变量)

Missing required parameters for [Route: dashboard2] [URI: dashboard2/{wordsRowB}/{wordsRowId}].
in UrlGenerationException.php line 17
at UrlGenerationException::forMissingParameters(object(Route)) in UrlGenerator.php line 332
at UrlGenerator->toRoute(object(Route), array(), true) in UrlGenerator.php line 304
at UrlGenerator->route('dashboard2', array()) in Redirector.php line 157
at Redirector->route('dashboard2') in DashController.php line 323
at DashController->postPin('62', '1', '39', 'kokowawa')
at call_user_func_array(array(object(DashController), 'postPin'), array('post_id' => '62', 'user_id' => '1', 'wordsRowB' => '39', 'wordsRowId' => 'kokowawa')) in Controller.php line 80

请注意,使用 var_dump 表明变量被传递给 postPin 函数,但我不知道如何检查它们是否成功重定向到路由?

我认为您的变量需要在route()调用范围内,请尝试返回:

redirect()->route('dashboard2', [$wordsRowId, $wordsRowB]);

像这样定义路由

redirect()->route('dashboard2', [$wordsRowId, $wordsRowB]);