Laravel 5.5:动态更改油门时间 [英] Laravel 5.5 : Dynamically change throttle time
问题描述
当前我正在使用登录油门,我必须动态更改第二油门的油门时间.
Currently i am working on login throttle, I have to change the throttle time on 2nd throttle dynamically.
我将如何做到这一点?
推荐答案
Middleware (such as throttle
) can be defined inside controllers as well.
一种解决方案是有条件地在控制器的构造函数中设置中间件,类似于:
A solution would be to conditionally set the middleware in the controllers' constructor, something along the lines of:
if (true) {
$this->middleware('throttle:60,1');
} else {
$this->middleware('throttle:30,1');
}
在Laravel 5.6中,您可以通过以下方式指定用户模型属性,该属性用于确定用户可以在提供的时间段(以分钟为单位)内发出的请求数:
In Laravel 5.6, here’s how you specify a User model attribute used to determine the number of requests a user can make within the provided timeframe (in minutes):
Route::middleware('throttle:rate_limit,1');
请参见 https://laravel-news.com/laravel-5-6-dynamic-rate-limiting 和文档以获取更多信息.
See https://laravel-news.com/laravel-5-6-dynamic-rate-limiting and the docs for more information.
祝你好运!
这篇关于Laravel 5.5:动态更改油门时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!