RouteServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. ->prefix('api')
  29. ->namespace('App\Http\Api')
  30. ->group(base_path('routes/api.php'));
  31. Route::middleware('web')
  32. ->namespace('App\Http\Home')
  33. ->group(base_path('routes/web.php'));
  34. Route::prefix('admin')
  35. ->middleware('admin')
  36. ->namespace('App\Http\Admin')
  37. ->group(base_path('routes/admin.php'));
  38. });
  39. }
  40. /**
  41. * Configure the rate limiters for the application.
  42. *
  43. * @return void
  44. */
  45. protected function configureRateLimiting()
  46. {
  47. RateLimiter::for('api', function (Request $request) {
  48. return Limit::perMinute(120)->by($request->user()?->id ?: $request->ip());
  49. });
  50. }
  51. }