如何优化laravel路由组中的使用控制器?

时间:2016-01-10 16:34:32

标签: php laravel laravel-5 laravel-5.1 laravel-routing

Route::group(['as' => 'admin.documents', 'middleware' => 'permissions:volunteer', 'prefix' => 'admin/documents/', 'namespace' => 'Admin/'], function () {
    Route::get('', ['uses' => 'AdminDocumentsController@index',    'as' => '',         ]);
    Route::get('add', ['uses' => 'AdminDocumentsController@create',   'as' => '.create',  ]);
    Route::post('add', ['uses' => 'AdminDocumentsController@create',   'as' => '.create' 
});

如何优化此代码? 也找到命名空间,但AdminDocumentsController看起来不是商品

1 个答案:

答案 0 :(得分:1)

将名称空间添加到第一个路由组,然后从使用

中删除管理员
Route::group(['namespace' => 'Admin', 'as' => 'admin.documents', 'middleware' => 'permissions:volunteer', 'prefix' => 'admin/documents/'], function () {
    Route::get('', ['uses' => 'AdminDocumentsController@index',    'as' => '',         ]);
    Route::get('add', ['uses' => 'AdminDocumentsController@create',   'as' => '.create',  ]);
});