Reset Laravel Rate Limiting

Viewed 635

i want to implement laravel rate limiting using the laravel throttle middleware. i have no problem at all with implementing this, but i want to ask if is that possible to reset the restriction of this throttle middleware.

for example i have a login route and i limit it with 3 attempt per 10 minute, is there any way to reset the user restriction if there is a human error on the login attempt, so the user can try again?

i have try to find the laravel documentation about this but this is so limited and no one ever does this. is this even possible to do?

2 Answers

Sadly, it is a little tricky to clear a Limiter used in RouteServiceProvider.

Following a Laravel 9.x documentation example:

RateLimiter::for('global', function (Request $request) {
    return Limit::perMinute(1000)->by($request->ip());
});

Laravel encodes your limiter key with md5 and appends your rate limiter name. So in the previous code, the $key would be md5('global'.request->ip()). Now you can clear your limiter using the following method RateLimiter::clear($key);

Hopes this helps.

If you are looking for a manual quick fix, this will work:

php artisan cache:clear

Related