Search code examples
laravellumenrate-limiting

Can I customize rate limiting in Laravel?


Is there any way through which the rate limit duration can be customized?

For instance, I am using the default Laravel rate limiter. I would want to have something like - allow 10 requests per hour.


Solution

  • Laravel throttle is a rate limiter for the Laravel application.

    You can make your request safe implementing laravel throttle by route group like :

    Route::group(['middleware' => 'throttle:10,60'], function () {
      Route::get('your_route', 'YourController@your_method');
      Route::post('your_route2', 'YourController@your_method2');
    });
    

    or

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

    Here 10 requests allowed in every 60 minutes (1 hour) by a single user or session IP. You have to test it on a live server. It would not work in localhost.