RouteServiceProvider.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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. * Typically, users are redirected here after authentication.
  14. *
  15. * @var string
  16. */
  17. public const HOME = '/home';
  18. /**
  19. * Define your route model bindings, pattern filters, and other route configuration.
  20. *
  21. * @return void
  22. */
  23. public function boot()
  24. {
  25. $this->configureRateLimiting();
  26. $this->routes(function () {
  27. Route::middleware('api')
  28. ->group(base_path('routes/api.php'));
  29. Route::middleware('web')
  30. ->group(base_path('routes/web.php'));
  31. });
  32. }
  33. /**
  34. * Configure the rate limiters for the application.
  35. *
  36. * @return void
  37. */
  38. protected function configureRateLimiting()
  39. {
  40. RateLimiter::for('api', function (Request $request) {
  41. return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
  42. });
  43. }
  44. }