RouteServiceProvider.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. * 管理后台API命名空间
  20. * @var string
  21. */
  22. protected $manageApiNameSpace = 'Modules\ManageApi\Controllers';
  23. /**
  24. * api命名空间
  25. * @var string
  26. */
  27. protected $apiNameSpace = 'Modules\Api\Controllers';
  28. /**
  29. * Define your route model bindings, pattern filters, and other route configuration.
  30. *
  31. * @return void
  32. */
  33. public function boot()
  34. {
  35. // $this->configureRateLimiting();
  36. $this->routes(function () {
  37. Route::middleware('api')
  38. ->prefix('api')
  39. ->namespace($this->apiNameSpace)
  40. ->group(base_path('routes/api.php'));
  41. Route::middleware('web')
  42. ->group(base_path('routes/web.php'));
  43. Route::prefix(env('MANAGE_API_URI_PREFIX', 'manage/api'))
  44. ->middleware('manage_api')
  45. ->namespace($this->manageApiNameSpace)
  46. ->group(base_path('routes/manage_api.php'));
  47. });
  48. }
  49. /**
  50. * Configure the rate limiters for the application.
  51. *
  52. * @return void
  53. */
  54. protected function configureRateLimiting()
  55. {
  56. RateLimiter::for('api', function (Request $request) {
  57. return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
  58. });
  59. }
  60. }