Laravel 5.7动态速率限制不起作用 [英] Laravel 5.7 dynamic rate limit not working

查看:61
本文介绍了Laravel 5.7动态速率限制不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的api路由中,我具有以下内容:

In my api routes I have the following:

Route::group(['middleware' => 'throttle:rate_limit,1', 'prefix' => 'recruiter/v1', 'namespace' => 'Api\Recruiter\V1'], function ()
{

    Route::get('/products', 'ProductController@index');
 });

rate_limit 参数是我的用户表中的一个字段,设置为100,但是每分钟60次点击后,我似乎达到了极限.

The rate_limit parameter is a field in my users table and is set to 100 but after 60 hits per minute i seem to reach the limit.

在kernal.php中,我有:

In kernal.php I have:

'api' => [
        'throttle:60,1',
        'bindings',
],

现在,文档中没有提及有关使用动态速率限制时需要对以上内容进行注释的任何内容吗?

now the docs doesn't mention anything about needing to comment the above out when using dynamic rate limit?

我认为动态速率限制的整个想法是可以设置您自己的限制,但显然不能-kernal.php中定义的值会覆盖任何其他值,除非它低于kernal.php中定义的值.

I thought the whole idea of dynamic rate limit was being able to set your own limit but clearly not - whatever is defined in kernal.php overides any other value unless it below the value define in kernal.php.

推荐答案

您节流了两次.一次在您创建的组中,一次在api中.

You are throttling twice. Once in the group you created, and once in the api.

如果您在主RouteServiceProvider中查看,则会看到api文件被您在内核中设置的api恶意软件所包围.

If you look in the main RouteServiceProvider you will see that the api file is surrounded with the api milddleware you set in the Kernel.

它限制api.php文件中的所有路由.

It throttles ALL the routes inside the api.php file.

为避免这种情况,请从内核中的api上删除节流阀,将路由移出api.php并制作另一个路由文件,或者可以更改服务提供商以反映所需的更改.

To avoid this remove the throttle from the api in Kernel, move your routes out of the api.php and make another routes file or you could change the service provider to reflect your changes you need.

这篇关于Laravel 5.7动态速率限制不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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