Laravel 5.6 Dynamic Rate Limiting

973

Starting from Laravel 5.6, you can use dynamic rate limiting to specify maximum number of requests based on the attribute of the authenticated User model.

When specifying a rate limit on a group of routes in previous versions of Laravel, you had to provide a hard-coded number of maximum requests. This is how you define rate limiting in previous versions of Laravel:

Route::middleware('auth:api', 'throttle:60,1')->group(function () {
    Route::get('/user', function () {
        //
    });
});

From Laravel 5.6, you can specify maximum number of requests in a specific time-frame from a specific User model attribute.

Route::middleware('auth:api', 'throttle:rate_limit,1')->group(function () {
    Route::get('/user', function () {
        //
    });
});

Laravel 5.6 is due next week. Checkout Laravel 5.6 Release Notes which provides the details for changes to the framework.

You might also like
Comments