尽管在URL中显示id,但缺少Route的必需参数

时间:2017-10-23 16:08:28

标签: php laravel blade

我遇到了一个小问题 - 我收到以下错误消息:Missing required parameters for [Route: teachers.forums.show] [URI: teachers/forums/{forum}]

我知道这意味着什么。但是,我没有看到我出错的地方。我显然忽视了一些事情。我已尝试过在其他类似问题上发布的内容,但无济于事。

网址中正确显示的网址,例如教师/论坛/ 91。我有针对$ forum的数据 - 其他所有内容都在索引页面上打印,如上所述,ID明显附加到URL。

routes.php文件

Route::group(['prefix' => 'forums'], function() {
    Route::get('/dashboard', ['as' => 'teachers.forums.dashboard', 'uses' => 'ForumsController@dashboard']);

    Route::get('/', ['as' => 'teachers.forums.index', 'uses' => 'ForumsController@index']);
    Route::post('/', ['as' => 'teachers.forums.add', 'uses' => 'ForumsController@add']);

    // route not working properly!
    Route::get('/{forum}', ['as' => 'teachers.forums.show', 'uses' => 'ForumsController@show']);                    
});

查看(blade.php)

<a href="{{route('teachers.forums.show', $forum->id)}}" class="load_more_post">
    <i class="fa fa-angle-right load-right-angle" aria-hidden="true"></i>
</a>

控制器

public function show(Forum $forum)
{
    $teacher = User::getTeacher($this->selectedClass->id);
    $forumQuestionMessages = ForumQuestion::getQuestions($forum);

    return view('teachers.forums.show', compact('teacher', 'forum', forumQuestionMessages'));

}

帮助将不胜感激!!

2 个答案:

答案 0 :(得分:2)

尝试将参数传递给路由,如下所示:

{!! route('teachers.forums.show', ['forum' => $forum->id]) !!}

答案 1 :(得分:1)

试一试

<a href="{{route('teachers.forums.show', ['forum' => $forum->id])}}" class="load_more_post">
   <i class="fa fa-angle-right load-right-angle" aria-hidden="true"></i>
</a>