RouteServiceProvider.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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->mapWebRoutes();
  34. //后台路由
  35. $this->mapAdminRoutes();
  36. $this->mapTeacherRoutes();
  37. }
  38. public function mapAdminRoutes()
  39. {
  40. Route::prefix('admin')
  41. ->middleware('web')
  42. ->namespace($this->namespace. '\Admin')
  43. ->group(base_path('routes/admin.php'));
  44. }
  45. public function mapTeacherRoutes()
  46. {
  47. Route::prefix('teacher')
  48. ->middleware('web')
  49. ->namespace($this->namespace. '\Teacher')
  50. ->group(base_path('routes/teacher.php'));
  51. }
  52. /**
  53. * Define the "web" routes for the application.
  54. *
  55. * These routes all receive session state, CSRF protection, etc.
  56. *
  57. * @return void
  58. */
  59. protected function mapWebRoutes()
  60. {
  61. Route::middleware('web')
  62. ->namespace($this->namespace)
  63. ->group(base_path('routes/web.php'));
  64. }
  65. /**
  66. * Define the "api" routes for the application.
  67. *
  68. * These routes are typically stateless.
  69. *
  70. * @return void
  71. */
  72. protected function mapApiRoutes()
  73. {
  74. Route::prefix('api')
  75. ->middleware('api')
  76. ->namespace($this->namespace)
  77. ->group(base_path('routes/api.php'));
  78. }
  79. }