问题
Currently i am working on login throttle, I have to change the throttle time on 2nd throttle dynamically.
How will i be able to do that ?
回答1:
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');
}
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');
See https://laravel-news.com/laravel-5-6-dynamic-rate-limiting and the docs for more information.
Good luck!
来源:https://stackoverflow.com/questions/51856113/laravel-5-5-dynamically-change-throttle-time