关于Laravel路由问题
1. 运行环境
LNMP
1). 当前使用的 Laravel 版本?
Laravel Framework 8.83.25
2). 当前使用的 php/php-fpm 版本?
PHP 7.4.3
3). 当前系统
CentOS8
4). 业务环境
开发环境
5). 相关软件版本
Nginx
2. 问题描述?
我有两个路由文件,routes/web.php,routes/api.php, 在RouteServiceProvider代码如下:
Route::prefix('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::namespace('Web')->group(function () {
// 调试
echo 'Router.web';
Route::get('/', App\Http\Controller\Web\IndexController::class, 'index');
})
Route::namespace('Api')->prefix('v1')->group(function () {
// 调试
echo 'Router.api';
Route::get('/', App\Http\Controller\Web\IndexController::class, 'index');
})
现在在问题是在每一次请求他都会执行router/api.php 写的 echo ‘Router.api’
按照我的理解,我即然是web过来的,通过名称空间过滤不应该走Api的
在这个试验里,虽然请求最终会落到web.php配的路由里,但是每次请求他要遍历所有的路由文件以及配置项,我想问的是怎么让路由精确的定位某个路由文件上
推荐文章: