【发布时间】: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 函数,但我不知道如何检查它们是否成功重定向到路由?
【问题讨论】: