RouteServiceProvider.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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->routes(function () {
  36. Route::middleware('web')
  37. ->namespace($this->namespace)
  38. ->group(base_path('routes/web.php'));
  39. });
  40. }
  41. /**
  42. * Configure the rate limiters for the application.
  43. *
  44. * @return void
  45. */
  46. protected function configureRateLimiting()
  47. {
  48. RateLimiter::for('api', function (Request $request) {
  49. return Limit::perMinute(60);
  50. });
  51. }
  52. protected function mapApiRoutes()
  53. {
  54. Route::prefix('api')
  55. ->middleware('api')
  56. ->namespace($this->namespace)
  57. ->group(base_path('routes/api.php'));
  58. //dd($this->namespace);
  59. foreach ( glob(base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR).'*.php' ) as $fileName ) {
  60. $fileName = basename( $fileName );
  61. Route::middleware('api_verify')
  62. ->namespace( $this->namespace."\\Api" )
  63. ->prefix('api')
  64. ->group( base_path('routes'.DIRECTORY_SEPARATOR.'api'.DIRECTORY_SEPARATOR."{$fileName}") );
  65. }
  66. }
  67. }