RouteServiceProvider.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Providers;
  3. use Catch\CatchAdmin;
  4. use Illuminate\Cache\RateLimiting\Limit;
  5. use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Routing\CompiledRouteCollection;
  8. use Illuminate\Support\Facades\RateLimiter;
  9. use Illuminate\Support\Facades\Route;
  10. class RouteServiceProvider extends ServiceProvider
  11. {
  12. /**
  13. * The path to the "home" route for your application.
  14. *
  15. * Typically, users are redirected here after authentication.
  16. *
  17. * @var string
  18. */
  19. public const HOME = '/home';
  20. /**
  21. * Define your route model bindings, pattern filters, and other route configuration.
  22. *
  23. * @return void
  24. */
  25. public function boot()
  26. {
  27. $this->configureRateLimiting();
  28. $this->routes(function () {
  29. Route::middleware('api')
  30. ->prefix('api')
  31. ->group(base_path('routes/api.php'));
  32. Route::middleware('web')
  33. ->group(base_path('routes/web.php'));
  34. });
  35. $this->booted(function(){
  36. $this->app->booted(function (){
  37. if (file_exists('loadCachedAdminRoutes')) {
  38. loadCachedAdminRoutes();
  39. }
  40. });
  41. });
  42. }
  43. /**
  44. * Configure the rate limiters for the application.
  45. *
  46. * @return void
  47. */
  48. protected function configureRateLimiting()
  49. {
  50. RateLimiter::for('api', function (Request $request) {
  51. return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
  52. });
  53. }
  54. }