Route::get('forum/{ques}', "ForumQuestionsController@show");
现在我想要一条路线
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController@add"]);
好吧,当我点击localhost:800 /论坛/添加我被路由到ForumQuestionsController @ show而不是ForumQuestionsController @ add
嗯,我知道我可以在ForumQuestionsController的show方法中处理它,并根据参数返回不同的视图.但我想以这种方式.
解决方法:
先给这一个
Route::get('forum/add', ['middleware' => 'auth:student', 'uses' => "ForumQuestionsController@add"]);
然后是以下
Route::get('forum/{ques}', "ForumQuestionsController@show");
另一种方法(使用正则表达式约束)
Route::pattern('ques', '[0-9]+');
Route::get('forum/{ques}', "ForumQuestionsController@show");