laravel 路由,如何在一个文件中分组相似

laravel routes, how to group similar in one file

我正在使用 laravel(5.2),我的路由文件中有很多路由。

在全新安装中,我注意到它正在加载 auth 类似这样的路由。

Route::auth();

routes.php 文件中没有其他与 auth 路线相关的内容。

在我的档案里,我喜欢这个

Route::get('color/event', 'ColorController@index');
Route::post('color/event', 'ColorController@post_message);
...
...

和许多其他人,所以我想以 laravel 方式加载所有内容,例如 Route::color(); 并且它应该加载所有与颜色相关的 routes

谢谢你的时间

你可以试试这个

Route::resource('admin/settings','Admin\SettingsController');

并尝试这个命令

$ php artisan routes

使用Route::get()Route::post()和类似的函数是以 Laravel 方式进行 - 请参阅此处的文档 https://laravel.com/docs/5.2/routing#basic-routing

Route::auth() 只是 Laravel 5.2 中引入的辅助函数,用于将所有身份验证定义放在一起。

所以,如果 s/he 正在寻找相同答案的任何人,我都知道了。

如果您想要 Route::auth();Route::color();//in my case 之类的名称或任何您想要的名称,您需要在 Router.php 文件中添加自定义 function。所以解决方案看起来像

//inside Router.php file
public function whatever(){
    $this->get('app/', 'AppController@index');
    $this->post('app/new', 'AppController@create');
}

在你的 route.php 文件中,你可以这样做。

Route::whatever();

但这真的很脏

所以您可以扩展基础 Router 并在 bootstrap/app.php

中注册您的路由器
$app->singleton('router', 'App\Your\Router');

所以我社区强制使用第二种方法。

更多详情,请看这里。

希望有人会觉得这有用

谢谢。