Laravel 5.4 - Override API 'throttle:60,1' Laravel 5.4 - Override API 'throttle:60,1' php php

Laravel 5.4 - Override API 'throttle:60,1'


Current answer

According to this GitHub issue, the throttle middleware should not be used "twice" (like you want to do that). There are only two ways how to deal with your current problem "correctly":

  1. Write an own throttling middleware

or

  1. Define the throttle middleware separately for each route (group)

Old answer

You set the middleware key wrong! When declaring multiple middleware to use, create a new array for them

['middleware' => ['WriteToDatabaseMiddleware','throttle:500,1']]

EDIT: Because of the middleware order, you should set your kernel throttle to the highest value you want to use, and all other routes that should have a lower throttle value to the corresponding ones.


In laravel 6 you can use prefix for prevent with global throttle.use 'throttle:5,1,prefix'

Route::group(['prefix' => 'contact-us', 'middleware' => 'throttle:5,1,contact-form',], function () {    Route::post('/', 'ContactUsController@store');});

Allow multiple throttles by naming


None of the current answers explain Laravel 5.x behaviour. In that version every instance of "throttle" uses the same bucket. So if you place a throttle command in two separate locations it affects every instance.

Consider:

// User can email 5 times an hourRoute::post('/email', 'Ctrl@email')->middleware('throttle:5,60');// User can search 100 times an hourRoute::get('/search', 'Ctrl@search')->middleware('throttle:100,60);

If a user searches 5 times in a 5 minute period, they will not able to email in the next hour.

In Laravel 5.x there is no way around this. In Laravel 6 onwards they added the ability to name throttles, giving them separate buckets.