鉴于以下路线,它将响应
http://example.com/game/stats/123
http://example.com/game/stats/game/123
http://example.com/game/stats/reviewer/123
我想知道的是,我该如何回应
http://example.com/game/123/stats
http://example.com/game/123/stats/game
http://example.com/game/123/stats/reviewer
我试过
Route::group(['prefix' => 'game/{game}'], function($game){
但是失败的是“缺少{closure}()的参数1”
请注意,除了统计数据之外还有其他四个组,但为了简洁起见,我省略了它们。
Route::group(['prefix' => 'game'], function(){
Route::group(['prefix' => 'stats'], function(){
Route::get('/{game}', ['as' => 'game.stats', function ($game) {
return View::make('competitions.game.allstats');
}]);
Route::get('game/{game}', ['as' => 'game.stats.game', function ($game) {
return View::make('competitions.game.gamestats');
}]);
Route::get('reviewer/{game}', ['as' => 'game.stats.reviewer', function ($game) {
return View::make('competitions.game.reviewstats');
}]);
});
});
答案 0 :(得分:5)
你能试试这段代码,看看它是不是你想要的。这里是第二组路由它只是{gameId}
,然后你有stats
组包装所有其他路由。
Route::group(['prefix' => 'game'], function(){
Route::group(['prefix' => '{gameId}'], function(){
Route::group(['prefix' => 'stats'], function(){
Route::get('/', ['as' => 'game.stats', function ($game) {
return View::make('competitions.game.allstats');
}]);
Route::get('game', ['as' => 'game.stats.game', function ($game) {
return View::make('competitions.game.gamestats');
}]);
Route::get('reviewer', ['as' => 'game.stats.reviewer', function ($game) {
return View::make('competitions.game.reviewstats');
}]);
});
});
});
然后在您的观看中,您可以通过路线名称呼叫它们并将gameId
传递给路线;
{{ link_to_route('game.stats','All Stats',123) }} // game/123/stats/
{{ link_to_route('game.stats.game','Game Stats',123) }} // game/123/stats/game
{{ link_to_route('game.stats.reviewer','Review Stats',123) }} // game/123/stats/reviewer
希望这有助于解决您的问题。
修改强>
我刚刚检查过它应该与Route::group(['prefix' => 'game/{game}'
一起使用,但是只要确保在创建如上所述的路由时传递game
参数。如果要传递更多变量,可以将数组传递给函数。
{{ link_to_route('game.stats','All Stats',['game' => '123','someOtherVar' => '456']) }}