Laravel 5.3 和 5.4 自定义路由文件
Laravel 5.3 and 5.4 Custom Route File
根据Laravel文档,在路由部分,位于路由目录中的文件由框架自动加载。
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework.
因此,我尝试在此目录中创建另一个名为 auth.php
的文件来处理我的自定义身份验证路由。但是,未加载此文件中定义的路由。
可以使用这种方式,还是需要注册服务商才能加载自定义路由文件?
您需要在您的 RouteServiceProvider.php 中映射路由,查看网络路由示例。
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}
根据Laravel文档,在路由部分,位于路由目录中的文件由框架自动加载。
All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by the framework.
因此,我尝试在此目录中创建另一个名为 auth.php
的文件来处理我的自定义身份验证路由。但是,未加载此文件中定义的路由。
可以使用这种方式,还是需要注册服务商才能加载自定义路由文件?
您需要在您的 RouteServiceProvider.php 中映射路由,查看网络路由示例。
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*
* @return void
*/
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function ($router) {
require base_path('routes/web.php');
});
}