RouteServiceProvider.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. if (request()->input('route') != 'geetest') {
  54. Route::middleware('web')
  55. ->namespace($this->namespace)
  56. ->group(base_path('routes/web.php'));
  57. } else {
  58. Route::middleware('web')
  59. ->group(base_path('routes/web.php'));
  60. }
  61. }
  62. /**
  63. * Define the "api" routes for the application.
  64. *
  65. * These routes are typically stateless.
  66. *
  67. * @return void
  68. */
  69. protected function mapApiRoutes()
  70. {
  71. Route::prefix('api')
  72. ->middleware('api')
  73. ->namespace($this->namespace)
  74. ->group(base_path('routes/api.php'));
  75. }
  76. }