请确认以下步骤是否正确(特别是返回重定向()部分)
路线"仪表板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]);
我收到此错误:(您还会在错误中找到另外两个变量,为清晰起见,我从上面的代码中删除了这些变量)
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函数,但我不知道如何检查它们是否已成功重定向到路径?
答案 0 :(得分:1)
我认为您的变量需要在#list
调用范围内,请尝试返回:
route()
答案 1 :(得分:0)
这样定义您的路线
redirect()->route('dashboard2', [$wordsRowId, $wordsRowB]);