Gammer
Gammer

Reputation: 5608

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.

How will i be able to do that ?

Upvotes: 1

Views: 2129

Answers (1)

JasonK
JasonK

Reputation: 5294

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!

Upvotes: 1

Related Questions