RouteServiceProvider.php 1.7 KB

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