DEV Community

Cover image for Laravel 9 - Rate Limiting: Global and for Guests/Users
Sandro Jhuliano Cagara
Sandro Jhuliano Cagara

Posted on

3

Laravel 9 - Rate Limiting: Global and for Guests/Users

You can limit some URL to be called a maximum of 60 times per minute, with throttle:60,1:

Route::middleware('auth:api', 'throttle:60,1')->group(function () {
    Route::get('/user', function () {
        // code here
    });
});
Enter fullscreen mode Exit fullscreen mode

But also, you can do it separately for public and for logged-in users:
Reminder: maximum of 10 requests for guests, 60 for authenticated users

Route::middleware('throttle:10|60,1')->group(function () {
    // code here
});
Enter fullscreen mode Exit fullscreen mode

Also, you can have a DB field users.rate_limit and limit the amount for specific user:

Route::middleware('auth:api', 'throttle:rate_limit,1')->group(function () {
    Route::get('/user', function () {
        // code here
    });
});
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more