RouteServiceProvider.php 2.1 KB

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