RouteServiceProvider.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  4. use Illuminate\Support\Facades\Route;
  5. class RouteServiceProvider extends ServiceProvider
  6. {
  7. /**
  8. * This namespace is applied to your controller routes.
  9. *
  10. * In addition, it is set as the URL generator's root namespace.
  11. *
  12. * @var string
  13. */
  14. protected $namespace = 'App\Http\Controllers';
  15. protected $apiNamespace = 'Modules\Api\Controllers';
  16. /**
  17. * 管理后台API命名空间
  18. * @var string
  19. */
  20. protected $manageApiNameSpace = 'Modules\ManageApi\Controllers';
  21. /**
  22. * 代理后台API命名空间
  23. * @var string
  24. */
  25. protected $agentApiNameSpace = 'Modules\AgentApi\Controllers';
  26. /**
  27. * 内部API控制器命名空间.
  28. * @var string
  29. */
  30. protected $innerApiNS = 'Modules\InnerApi\Controllers';
  31. /**
  32. * The path to the "home" route for your application.
  33. *
  34. * @var string
  35. */
  36. public const HOME = '/home';
  37. /**
  38. * Define your route model bindings, pattern filters, etc.
  39. *
  40. * @return void
  41. */
  42. public function boot()
  43. {
  44. //
  45. parent::boot();
  46. }
  47. /**
  48. * Define the routes for the application.
  49. *
  50. * @return void
  51. */
  52. public function map()
  53. {
  54. // $this->mapApiRoutes();
  55. $this->mapWebRoutes();
  56. $this->mapManageApiRoutes();
  57. $this->mapAgentApiRoutes();
  58. $this->mapInnerApiRoutes();
  59. }
  60. /**
  61. * Define the "web" routes for the application.
  62. *
  63. * These routes all receive session state, CSRF protection, etc.
  64. *
  65. * @return void
  66. */
  67. protected function mapWebRoutes()
  68. {
  69. Route::middleware('web')
  70. ->namespace($this->namespace)
  71. ->group(base_path('routes/web.php'));
  72. }
  73. /**
  74. * Define the "api" routes for the application.
  75. *
  76. * These routes are typically stateless.
  77. *
  78. * @return void
  79. */
  80. protected function mapApiRoutes()
  81. {
  82. Route::prefix('api')
  83. ->middleware('api')
  84. ->name('api::')
  85. ->namespace($this->apiNamespace)
  86. ->group(base_path('routes/api.php'));
  87. }
  88. /**
  89. * 管理后台API路由定义引用配置.
  90. */
  91. protected function mapManageApiRoutes()
  92. {
  93. Route::prefix(env('MANAGE_API_URI_PREFIX', 'admin/api'))
  94. ->middleware(['manage_api'])
  95. ->name('manage_api::')
  96. ->namespace($this->manageApiNameSpace)
  97. ->group(base_path('routes/manage_api.php'));
  98. }
  99. /**
  100. * 代理后台API路由定义引用配置.
  101. */
  102. protected function mapAgentApiRoutes()
  103. {
  104. Route::prefix(env('AGENT_API_URI_PREFIX', 'agent/api'))
  105. ->middleware(['agent_api'])
  106. ->name('agent_api::')
  107. ->namespace($this->agentApiNameSpace)
  108. ->group(base_path('routes/agent_api.php'));
  109. }
  110. /**
  111. * 定义内部API路由基础配置.
  112. * @return void
  113. */
  114. protected function mapInnerApiRoutes()
  115. {
  116. Route::prefix('inner/api')
  117. ->middleware('inner_api')
  118. ->name('inner_api::')
  119. ->namespace($this->innerApiNS)
  120. ->group(base_path('routes/inner_api.php'));
  121. }
  122. }