Rate Limiting Feature For Particular Route In Laravel 5.2

- 1 answer

I am using the below code that implements Rate Limiting feature for all Routes in a Group.

Route::group(['middleware' => ['web', 'throttle:2']], function () {
    Route::get('/CSR', array('uses' =>  '[email protected]', 'as' => 'CSRList'));
    //Second Route
    //Third Route
    //Fourth Route
    //Fifth Route

Question This works great. Is there any way to implement this for any particular route in a group ?



Of course you can. Any attribute you can assign to a route group can be assigned to a single route as well (in fact route groups really only apply their attributes sequentially to each of the routes contained within them, nothing more). So you can assign a middleware group such as api to a single route:

Route::get('/route/path', ['middleware' => 'api', 'uses' => '[email protected]']);

Or if you want to use just the throttling middleware you can use:

Route::get('/route/path', ['middleware' => 'throttle:2', 'uses' => '[email protected]']);

For more details on the rate limiting feature you can check out the Laracasts video linked below:

What's New in Laravel 5.2: API Rate Limiting