我想在Laravel中动态注册我的路线(端点) 。我没有使用routes.php,但我想使用注册路由
$this->app->get()
或类似的,在服务提供商中。此外,我还想以这种方式添加中间件来动态注册路由。
我想在Laravel中动态注册我的路线(端点) 。我没有使用routes.php,但我想使用注册路由
$this->app->get()
或类似的,在服务提供商中。此外,我还想以这种方式添加中间件来动态注册路由。
您可以查看您的RouteServiceProvider@map
inApp\Providers
以了解 Laravel 如何导入routes.php
文件。
然后,您可以导入 JSON 文件,将其转换为数组并循环遍历它。
您的 JSON 文件可能如下所示
[
{
"method": "get",
"uri": "/profile",
"action": {
"as": "profile",
"uses": "UserController@showProfile",
"middleware": "auth"
}
}
]
当您对此进行解码时,您可以执行类似的操作
\Route::$method($uri, $action);