RouteServiceProvider.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Providers;
  3. use Illuminate\Cache\RateLimiting\Limit;
  4. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\RateLimiter;
  7. use Illuminate\Support\Facades\Route;
  8. class RouteServiceProvider extends ServiceProvider
  9. {
  10. /**
  11. * The path to the "home" route for your application.
  12. *
  13. * This is used by Laravel authentication to redirect users after login.
  14. *
  15. * @var string
  16. */
  17. public const HOME = '/home';
  18. /**
  19. * The controller namespace for the application.
  20. *
  21. * When present, controller route declarations will automatically be prefixed with this namespace.
  22. *
  23. * @var string|null
  24. */
  25. protected $namespace = 'App\\Http\\Controllers';
  26. /**
  27. * Define your route model bindings, pattern filters, etc.
  28. *
  29. * @return void
  30. */
  31. public function boot()
  32. {
  33. $this->configureRateLimiting();
  34. $this->mapApiRoutes();
  35. $this->mapWpsRoutes();
  36. $this->routes(function () {
  37. Route::middleware('web')
  38. ->namespace($this->namespace)
  39. ->group(base_path('routes/web.php'));
  40. });
  41. }
  42. /**
  43. * Configure the rate limiters for the application.
  44. *
  45. * @return void
  46. */
  47. protected function configureRateLimiting()
  48. {
  49. RateLimiter::for('api', function (Request $request) {
  50. return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
  51. });
  52. }
  53. protected function mapApiRoutes()
  54. {
  55. Route::prefix('api')
  56. ->middleware('api')
  57. ->namespace($this->namespace)
  58. ->group(base_path('routes/api.php'));
  59. //dd($this->namespace);
  60. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  61. $fileName = basename( $fileName );
  62. Route::middleware('api_verify')
  63. ->namespace( $this->namespace."\\Api" )
  64. ->prefix('api')
  65. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR."{$fileName}") );
  66. }
  67. }
  68. /**
  69. * Wps回调地址
  70. */
  71. function mapWpsRoutes(){
  72. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'wps'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  73. $fileName = basename( $fileName );
  74. Route::namespace( $this->namespace."\\Wps" )
  75. ->prefix('wps')
  76. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'wps'.DIRECTORY_SEPARATOR."{$fileName}") );
  77. }
  78. }
  79. }