php - limiting - laravel throttlerequests
Disable rate limiter in Laravel? (4)
Assuming you are using the API routes then you can change the throttle in app/Http/Kernel.php or take it off entirely. If you need to throttle for the other routes you can register the middleware for them separately.
(example below: throttle - 60 attempts then locked out for 1 minute)
'api' => [
'throttle:60,1',
'bindings',
],
Is there a way to disable rate limiting on every/individual routes in Laravel?
I'm trying to test an endpoint that receives a lot of requests, but randomly Laravel will start responding with { status: 429, responseText: 'Too Many Attempts.' }
for a few hundred requests which makes testing a huge pain.
If you want to disable just for automated tests, you can use the WithoutMiddleware
trait on your tests.
use Illuminate\Foundation\Testing\WithoutMiddleware;
class YourTest extends TestCase {
use WithoutMiddleware;
...
Otherwise, just remove the 'throttle:60,1',
line from your Kernel file (app/Http/Kernel.php
), and your problem will be solved.
In Laravel 5.7
Dynamic Rate Limiting You may specify a dynamic request maximum based on an attribute of the authenticated User model. For example, if your User model contains a rate_limit attribute, you may pass the name of the attribute to the throttle middleware so that it is used to calculate the maximum request count:
Route::middleware('auth:api', 'throttle:rate_limit,1')->group(function () {
Route::get('/user', function () {
//
});
});
You can actually disable only a certain middleware in tests.
use Illuminate\Routing\Middleware\ThrottleRequests;
class YourTest extends TestCase
{
protected function setUp()
{
parent::setUp();
$this->withoutMiddleware(
ThrottleRequests::class
);
}
...
}