+2 votes
in Laravel by
What is throttling and how to implement it in Laravel?

1 Answer

0 votes
by

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 add it to a particular route:

Route::middleware('auth:api', 'throttle:60,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 60 times in a minute.

Related questions

0 votes
asked Jun 27, 2023 in Laravel by Robindeniel
+2 votes
asked Jul 10, 2021 in Laravel by SakshiSharma
...