我可以在Laravel中自定义速率限制吗? [英] Can I customize rate limiting in Laravel?

查看:70
本文介绍了我可以在Laravel中自定义速率限制吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过任何方式自定义速率限制持续时间?

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

例如,我正在使用默认的Laravel速率限制器.我希望有这样的内容-每小时允许10个请求.

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

推荐答案

Laravel节流阀 是Laravel应用程序的速率限制器.

Laravel throttle is a rate limiter for the Laravel application.

您可以通过以下路由组使您的请求安全地实施laravel节流阀:

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');
});

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

在单个用户或会话IP的每 60分钟 (1小时)中允许了 10 个请求.您必须在实时服务器上对其进行测试.在本地主机中将无法使用.

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.

这篇关于我可以在Laravel中自定义速率限制吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆