我正在尝试减少路径文件的大小并重新使用命名路由。我有两个经过身份验证的独立区域,并且有自己的专用路线,但是,它们共享很多共同的其他路线。
Route::group(['middleware' => 'web'], function () {
/**
* Author routes.
*/
Route::group(['prefix' => 'author', 'middleware' => 'auth'], function () {
Route::get('/', ['as' => 'dashboard', 'uses' => 'Controller@showHome']);
// ...various routes unique to authors...
Route::any('posts/data', ['as' => 'posts.data'])->uses('PostsController@data');
Route::get('posts/{account?}', ['as' => 'posts.show'])->uses('PostsController@index');
Route::get('posts/{post}/delete', ['as' => 'posts.delete'])->uses('PostsController@destroy');
Route::resource('posts', 'PostsController', ['parameters' => 'singular']);
// ...lots more routes like the above shared with reviewers...
});
/**
* Reviewer routes.
*/
Route::group(['prefix' => 'reviewer', 'middleware' => 'auth'], function () {
Route::get('/', ['as' => 'dashboard', 'uses' => 'Controller@showHome']);
// ...various routes unique to reviewers...
Route::any('posts/data', ['as' => 'posts.data'])->uses('PostsController@data');
Route::get('posts/{account?}', ['as' => 'posts.show'])->uses('PostsController@index');
Route::get('posts/{post}/delete', ['as' => 'posts.delete'])->uses('PostsController@destroy');
Route::resource('posts', 'PostsController', ['parameters' => 'singular']);
// ...lots more routes like the above shared with authors...
});
});
我仍然需要审稿人前往example.com/reviewer/posts
进行所有与帖子相关的活动和作者才能转到example.com/author/posts
。
我怎样才能减少冗长呢?
答案 0 :(得分:1)
创建单独的路线文件,例如post_routes.php
并将所有共享的Post
路由放在那里。
包含路线文件
Route::group(['prefix' => 'author', 'middleware' => 'auth'], function () {
require app_path('Http/post_routes.php');
});
/**
* Reviewer routes.
*/
Route::group(['prefix' => 'reviewer', 'middleware' => 'auth'], function () {
require app_path('Http/post_routes.php');
});