I'm using ThrottleRequest to throttle login attempts. In Kendler.php i have
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
and my route in web.php
Route::post('login', ['middleware' => 'throttle:3,1', 'uses' => 'Auth\LoginController@authenticate']);
When i login fourth time, it return status 429 with message 'TOO MANY REQUESTS.'
(by default i guess)
But i just want to return error message, somethings like:
return redirect('/login')
->withErrors(['errors' => 'xxxxxxx']);
Anybody help me! THANK YOU!
Laravel utilizes throttle middleware to limit the amount of traffic for a given route or gather of routes. The throttle middleware accepts two parameters that decide the maximum number of requests that can be made in a given number of minutes.
Laravel includes a simple to use rate limiting abstraction which, in conjunction with your application's cache, provides an easy way to limit any action during a specified window of time. If you are interested in rate limiting incoming HTTP requests, please consult the rate limiter middleware documentation.
Laravel has a fixed decay rate limiter. With default settings of throttle:60,1 this means that a client could make 60 requests with 1 minute of decay before hitting a 1 minute forced decay timeout. The client could make 60 requests in 1 second or distributed over 60 seconds at a rate of 1 request per second ( 1 r/s ).
Registering Middleware If you want a middleware to run during every HTTP request to your application, list the middleware class in the $middleware property of your app/Http/Kernel.php class.
You can either extend the middleware and override the buildException()
method to change the message it passes when it throws a ThrottleRequestsException
or you can use your exception handler to catch the ThrottleRequestsException
and do whatever you want.
so in Exceptions/Handler.php
you could do something like
use Illuminate\Http\Exceptions\ThrottleRequestsException;
public function render($request, Exception $exception)
{
if ($exception instanceof ThrottleRequestsException) {
//Do whatever you want here.
}
return parent::render($request, $exception);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With