RouteServiceProvider.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. protected $api_namespace = 'App\Http\Controllers\Api';
  16. protected $wechat_namespace = 'App\Http\Controllers\WeChat';
  17. /**
  18. * Define your route model bindings, pattern filters, etc.
  19. *
  20. * @return void
  21. */
  22. public function boot()
  23. {
  24. //
  25. parent::boot();
  26. }
  27. /**
  28. * Define the routes for the application.
  29. *
  30. * @return void
  31. */
  32. public function map()
  33. {
  34. $this->mapApiRoutes();
  35. $this->mapWebRoutes();
  36. //后台路由
  37. $this->mapAdminRoutes();
  38. $this->mapTeacherRoutes();
  39. $this->mapWeChatRoutes();
  40. }
  41. public function mapAdminRoutes()
  42. {
  43. Route::prefix('admin')
  44. ->middleware('web')
  45. ->namespace($this->namespace. '\Admin')
  46. ->group(base_path('routes/admin.php'));
  47. }
  48. public function mapTeacherRoutes()
  49. {
  50. Route::prefix('teacher')
  51. ->middleware('web')
  52. ->namespace($this->namespace. '\Teacher')
  53. ->group(base_path('routes/teacher.php'));
  54. }
  55. public function mapWeChatRoutes()
  56. {
  57. Route::prefix('wechat')
  58. ->middleware('web')
  59. ->namespace($this->wechat_namespace)
  60. ->group(base_path('routes/wechat.php'));
  61. }
  62. /**
  63. * Define the "web" routes for the application.
  64. *
  65. * These routes all receive session state, CSRF protection, etc.
  66. *
  67. * @return void
  68. */
  69. protected function mapWebRoutes()
  70. {
  71. Route::middleware('web')
  72. ->namespace($this->namespace)
  73. ->group(base_path('routes/web.php'));
  74. }
  75. /**
  76. * Define the "api" routes for the application.
  77. *
  78. * These routes are typically stateless.
  79. *
  80. * @return void
  81. */
  82. protected function mapApiRoutes()
  83. {
  84. Route::prefix('api')
  85. ->middleware('api')
  86. ->namespace($this->api_namespace)
  87. ->group(base_path('routes/api.php'));
  88. }
  89. }