扫码关注官方订阅号
84669人学习
65727人学习
82984人学习
467778人学习
498837人学习
471966人学习
256484人学习
152542人学习
224170人学习
139536人学习
81804人学习
85022人学习
11944人学习
20001人学习
60816人学习
5487人学习
15007人学习
2150人学习
6980人学习
194925人学习
359900人学习
1142人学习
19058人学习
3206人学习
180550人学习
48569人学习
17603人学习
40936人学习
1049人学习
750人学习
32909人学习
找到app/providers/RouteServiceProvider.PHP文件
<?php namespace App\Providers; use Illuminate\Routing\Router; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; class RouteServiceProvider extends ServiceProvider { /** * This namespace is applied to the controller routes in your routes file. * * In addition, it is set as the URL generator's root namespace. * * @var string */ protected $namespace = 'App\Http\Controllers'; protected $backendNamespace; protected $frontendNamespace; protected $apiNamespace; protected $currentDomain; /** * Define your route model bindings, pattern filters, etc. * * @param \Illuminate\Routing\Router $router * @return void */ public function boot(Router $router) { $this->backendNamespace = 'App\Http\Controllers\Backend'; $this->frontendNamespace = 'App\Http\Controllers\Frontend'; $this->apiNamespace = 'App\Http\Controllers\API'; //$this->currentDomain = $this->app->request->server->get('HTTP_HOST'); $this->currentDomain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ""; parent::boot($router); } /** * Define the routes for the application. * * @param \Illuminate\Routing\Router $router * @return void */ public function map(Router $router) { //$router->group(['namespace' => $this->namespace], function ($router) { //require app_path('Http/routes.php'); //}); $backendUrl = config('route.backend_url'); $frontendUrl = config('route.frontend_url'); $apiUrl = config('route.api_url'); switch ($this->currentDomain){ case $apiUrl: // API路由 $router->group([ 'domain' => $apiUrl, 'namespace' => $this->apiNamespace], function ($router) { require app_path('Http/routes-api.php'); } ); break; case $backendUrl: // 后端路由 $router->group([ 'domain' => $backendUrl, 'namespace' => $this->backendNamespace], function ($router) { require app_path('Http/routes-backend.php'); } ); break; default: // 前端路由 $router->group([ 'domain' => $frontendUrl, 'namespace' => $this->frontendNamespace], function ($router){ require app_path('Http/routes-frontend.php'); } ); break; } } }
完成后我们的路由也可以新建了 但要和上面的名称要一样
在路由中可以这样写(当然也可以自定义路由)例:
Route::group(['middleware' => ['web']], function () { Route::controller('/test', 'TestController'); // 重置 Route::get('user/password/reset/{token?}', [ 'as' => 'user.password.reset@token', 'uses' => 'User\PasswordController@getReset' ]); ]);
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
扫描下载App
Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
精品班
技术支持
技术咨询
学习群
会员优惠
返回顶部
找到app/providers/RouteServiceProvider.PHP文件
完成后我们的路由也可以新建了 但要和上面的名称要一样
在路由中可以这样写(当然也可以自定义路由)例: