gpt4 book ai didi

laravel-5 - 在同一组下添加路由类别的更好方法

转载 作者:行者123 更新时间:2023-12-02 22:26:10 24 4
gpt4 key购买 nike

我使用的是 Laravel 5.4

路线服务提供商代码如下

Route::prefix('api/v1')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/Login.php'));

Route::prefix('api/v1')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/Register.php'));

有什么办法可以将两个路由文件写在同一个组下吗?

类似这样的事情...

Route::prefix('api/v1')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/Login.php'))
->group(base_path('routes/Register.php'));

在 5.3 中。我们可以这样写...

Route::group([
'middleware' => 'auth:api',
'namespace' => $this->namespace,
'prefix' => 'api/v1',
], function ($router) {
require base_path('routes/API/Driver/Driver.php');
require base_path('routes/API/Vehicle/Vehicle.php');
});

最佳答案

您可以在5.4中使用与5.3中相同的解决方案

    Route::group(['prefix' => 'api', /* .... */], function () {

// extract this to external files as needed
Route::get('/path', 'HomeController@method');

});

关于laravel-5 - 在同一组下添加路由类别的更好方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42221706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com