Can I customize rate limiting in Laravel?

99封情书 提交于 2021-01-29 11:17:11

问题


Is there any way through which the rate limit duration can be customized?

For instance, I am using the default Laravel rate limiter. I would want to have something like - allow 10 requests per hour.


回答1:


Laravel throttle is a rate limiter for the Laravel application.

You can make your request safe implementing laravel throttle by route group like :

Route::group(['middleware' => 'throttle:10,60'], function () {
  Route::get('your_route', 'YourController@your_method');
  Route::post('your_route2', 'YourController@your_method2');
});

or

Route::middleware('throttle:10,60')->group(function () {
  Route::get('/user', function () {
    //
  });
});

Here 10 requests allowed in every 60 minutes (1 hour) by a single user or session IP. You have to test it on a live server. It would not work in localhost.



来源:https://stackoverflow.com/questions/65479243/can-i-customize-rate-limiting-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!