簡體   English   中英

Laravel 5.3 Route ::沒有REST的資源

[英]Laravel 5.3 Route::resource without REST

我將Laravel 5.1升級到5.3並且路由有問題。

在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中生成我的路線

誰能幫我?

謝謝。

由於沒有::controller替代方法,如果您不想使用rest,則需要為每個操作創建單獨的路由:

Route::get('pages/{page_type}', 'Admin\AdminPagesController@getIndex');
Route::post('pages/{page_type}', 'Admin\AdminPagesController@postIndex');
....

似乎在Laravel 5.2中刪除了Route::controllers方法,從那時起我在文檔中找不到它,並且在Laravel 5.3中的Illuminate\\Routing\\Router.php文件中不存在

您必須分別為您的案例創建每條路線。 或者你可以簡單地使用Route::resource方法,你有什么反對呢? 您可以在Route::resource調用之前向資源添加額外的方法來聲明它們。

暫無
暫無

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

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