RouteServiceProvider.php 1.5 KB

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