RouteServiceProvider.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Support\Facades\Route;
  4. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  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. /**
  16. * Define your route model bindings, pattern filters, etc.
  17. *
  18. * @return void
  19. */
  20. public function boot()
  21. {
  22. //
  23. parent::boot();
  24. }
  25. /**
  26. * Define the routes for the application.
  27. *
  28. * @return void
  29. */
  30. public function map()
  31. {
  32. $this->mapApiRoutes();
  33. $this->mapShopApiRoutes();
  34. $this->mapWapRoutes();
  35. $this->mapWebRoutes();
  36. $this->mapWebsRoutes();
  37. //
  38. $this->mapAdminApiRoutes();
  39. }
  40. /**
  41. * Define the "web" routes for the application.
  42. *
  43. * These routes all receive session state, CSRF protection, etc.
  44. *
  45. * @return void
  46. */
  47. protected function mapWebRoutes()
  48. {
  49. Route::middleware('web')
  50. ->namespace($this->namespace)
  51. ->group(base_path('routes/web.php'));
  52. }
  53. /**
  54. * Define the "api" routes for the application.
  55. *
  56. * These routes are typically stateless.
  57. *
  58. * @return void
  59. */
  60. protected function mapApiRoutes()
  61. {
  62. Route::prefix('api')
  63. ->middleware('api')
  64. ->namespace($this->namespace)
  65. ->group(base_path('routes/api.php'));
  66. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  67. $fileName = basename( $fileName );
  68. Route::middleware('api_verify')
  69. ->namespace( $this->namespace."\\Api" )
  70. ->prefix('api')
  71. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR."{$fileName}") );
  72. }
  73. }
  74. /**
  75. * 店铺Api
  76. */
  77. protected function mapShopApiRoutes(){
  78. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'shopApi'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  79. $fileName = basename( $fileName );
  80. Route::middleware('shop_verify')
  81. ->namespace( $this->namespace."\\ShopApi" )
  82. ->prefix('shopApi')
  83. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'shopApi'.DIRECTORY_SEPARATOR."{$fileName}") );
  84. }
  85. }
  86. /**
  87. * Wap端
  88. */
  89. protected function mapWapRoutes()
  90. {
  91. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'wap'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  92. $fileName = basename( $fileName );
  93. Route::middleware('wap_verify')
  94. ->namespace( $this->namespace."\\Wap" )
  95. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'wap'.DIRECTORY_SEPARATOR."{$fileName}") );
  96. }
  97. }
  98. /**
  99. * web 路由规则
  100. * @return void
  101. */
  102. protected function mapWebsRoutes(){
  103. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  104. $fileName = basename( $fileName );
  105. $prefix = substr( $fileName,0,strrpos($fileName,'.') );
  106. $nameSpace = ucfirst($prefix);
  107. //中间件过滤加载
  108. Route::middleware('web','admin_verify')
  109. ->namespace( $this->namespace."\\{$nameSpace}" )
  110. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'web'.DIRECTORY_SEPARATOR."{$fileName}") );
  111. }
  112. }
  113. /**
  114. * 总后台API路由
  115. */
  116. protected function mapAdminApiRoutes(){
  117. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  118. $fileName = basename( $fileName );
  119. $prefix = substr( $fileName,0,strrpos($fileName,'.') );
  120. $nameSpace = ucfirst($prefix);
  121. //中间件过滤加载
  122. Route::middleware('adminApi_verify')
  123. ->namespace( $this->namespace."\\AdminApi" )
  124. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'adminApi'.DIRECTORY_SEPARATOR."{$fileName}") );
  125. }
  126. }
  127. }