2016-04-09 39 views
0

這裏是我所有的路線;Laravel路線名稱與資源上的參數

Route::group(['prefix' => 'admin'], function() { 
    Route::resource('surveys', 'SurveyController'); 
    Route::resource('surveys/{survey}/groups', 'GroupController'); 
    Route::resource('surveys/{survey}/groups/{group}/questions', 'QuestionController'); 
}); 

這是我的(許多)定義的路線之一;

METHOD = GET|HEAD 
URI = admin/surveys/{survey}/groups/{groups} 
Name = admin.surveys.{survey}.groups.show 
Action = App\Http\Controllers\[email protected] 

我怎麼能說這一點,並在group.id和在我看來,survey.id通(它使用twig_bridge如果該事項小枝)

我試過;

{{ route('admin.surveys.{survey}.groups.show', ['survey' => survey.id, group.id]) }} 

與其他類似的語法,但總能得到意想不到的標點錯誤

我沒有名字,這些路線自己。這是默認的Laravel時遵守命名約定。

回答

0

可以使用點語法來定義嵌套資源路線:

Route::group(['prefix' => 'admin'], function() { 
    Route::resource('surveys', 'SurveyController'); 
    Route::resource('surveys.groups', 'GroupController'); 
    Route::resource('surveys.groups.questions', 'QuestionController'); 
}); 

然後你可以路由到他們這樣的:

route('admin.surveys.groups.show', [$surveyId, $groupId]) 
route('admin.surveys.groups.questions.show', [$surveyId, $groupId, $questionId])