What is throttling and how to implement it in Laravel?

Published 2 days ago5 min read4 comments

Throttling is a process to rate-limit requests from a particular IP. This can be used to prevent DDOS attacks as well. For throttling, Laravel provides a middleware that can be applied to routes and it can be added to the global middlewares list as well to execute that middleware for each request.

Here’s how you can we add it to a particular route:

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

This will enable the /user route to be accessed by a particular user from a particular IP only 30 times in a minute.


Mahabubur Rahman Mar 14, 2023 - 07:00 PM