Laravel named route for resource controller

后端 未结 7 1174
一向
一向 2020-11-30 22:09

Using Laravel 4.2, is it possible to assign a name to a resource controller route? My route is defined as follows:

Route::resource(\'faq\', \'ProductFaqCont         


        
7条回答
  •  佛祖请我去吃肉
    2020-11-30 23:03

    For answer seekers with Laravel 5.5+ finding this page:

    Route::namespace('Admin')->prefix('admin')->name('admin.')->group(function () {
    
        Route::resource('users','UserController');
    
    });
    

    These options will result in the following for the Resource:

    • namespace() sets Controller namespace to \Admin\UserController

    • prefix() sets request URi to /admin/users

    • name() sets route name accessor to route('admin.users.index')

    In name() the DOT is intended, it is not a typo.

    Please let others know if this works in comments for any versions prior to Laravel 5.5, I will update my answer.

    Update:

    I can confirm that in Laravel 5.3 that the name method is not available. No confirmation yet if supported in 5.4

    Taylor accepted my PR to officially document this in 5.5:

    https://laravel.com/docs/5.5/routing#route-group-name-prefixes

提交回复
热议问题