2016-12-13 142 views
1

我將Laravel 5.1升級到5.3,並且有一些路由問題。Laravel 5.3路由::資源沒有REST

在Laravel 5.1我有航線,如:

Route::controllers([ 
    'pages/{page_type}'  => 'Admin\AdminPagesController', 
]); 

而且在控制器我有這樣的方法:

getIndex($type) 
postIndex($type, Request $request) 
getAdd($type) 
postAdd(Request $request) 
getEdit($type, $id) 
postEdit(Request $request, $id) and others... 

但是在5.3的時候,我創建路線:

Route::resource('pages/{page_type}', 'Admin\AdminPagesController'); 

我出現錯誤

NotFoundHttpException in RouteCollection.php line 161: 

Route pattern "/master/pages/{page_type}/{{page_type}}" cannot reference variable name "page_type" more than once. 

,它生成我的RESTful

路線

誰能幫助我?

謝謝。

回答

0

由於沒有替代::controller你需要爲每個動作創建單獨的途徑,如果你不想用得:

Route::get('pages/{page_type}', 'Admin\[email protected]'); 
Route::post('pages/{page_type}', 'Admin\[email protected]'); 
.... 
0

似乎Route::controllers方法已在Laravel 5.2被刪除,我可以此後在文檔中找不到它,並且Laravel 5.3中的Illuminate\Routing\Router.php文件中不存在

您必須爲您的情況單獨創建每個路由。或者你可以簡單地使用Route::resource方法,你有什麼反對呢?您可以在Route::resource調用之前向資源添加額外的方法來聲明它們。