【问题标题】:Laravel 5.3 Route::resource without RESTLaravel 5.3 Route::resource 没有 REST
【发布时间】:2016-12-13 09:37:25
【问题描述】:

我将 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 中生成我的路由

谁能帮帮我?

谢谢。

【问题讨论】:

    标签: laravel laravel-5.3


    【解决方案1】:

    由于没有替代::controller,如果您不想使用休息,则需要为每个操作创建单独的路线:

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

    【讨论】:

      【解决方案2】:

      似乎Route::controllers 方法已在 Laravel 5.2 中删除,此后我在文档中找不到它,并且在 Laravel 5.3 中的 Illuminate\Routing\Router.php 文件中不存在

      您必须为您的案例分别创建每条路线。或者你可以简单地使用Route::resource 方法,你有什么反对的?您可以在 Route::resource 调用之前向资源声明它们添加额外的方法。

      【讨论】:

        猜你喜欢
        • 2014-06-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-23
        • 2017-01-14
        • 1970-01-01
        • 2019-06-14
        • 2013-10-06
        相关资源
        最近更新 更多