簡體   English   中英

盡管在URL中顯示id,但缺少Route的必需參數

[英]Missing required parameters for Route despite displaying id in the URL

我有一個小問題 - 我收到以下錯誤消息: Missing required parameters for [Route: teachers.forums.show] [URI: teachers/forums/{forum}]

我知道這意味着什么。 但是,我沒有看到我出錯的地方。 我顯然忽略了一些東西。 我已經嘗試過在其他類似問題上發布的內容,但無濟於事。

URL在URL中正確顯示,例如teachers / forums / 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'));

}

幫助將不勝感激!!

嘗試將參數傳遞給路由,如下所示:

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

試一試

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM