【问题标题】:Missing parameters that are passed to route using return redirect - Laravel缺少使用返回重定向传递给路由的参数 - Laravel
【发布时间】:2016-07-12 21:59:17
【问题描述】:

请确认以下步骤是否正确(特别是return redirect()部分)

Route "Dashboard2" 需要如下 2 个变量来通过 getDashboard 函数打开 Dashboard 视图:

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 函数,但我不知道如何检查它们是否成功重定向到路由?

【问题讨论】:

    标签: php laravel


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      像这样定义你的路线

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-06-04
        • 1970-01-01
        • 2020-06-25
        • 2019-03-03
        • 2018-08-14
        • 2018-09-20
        • 2019-01-09
        • 2020-08-07
        相关资源
        最近更新 更多