Rate Limiting: Global and for Guests/Users

You can limit some URL to be called a maximum of 60 times per minute, with throttle:60,1:

1Route::middleware('auth:api', 'throttle:60,1')->group(function () {
2 Route::get('/user', function () {
3 //
4 });
5});

But also, you can do it separately for public and for logged-in users:

1// maximum of 10 requests for guests, 60 for authenticated users
2Route::middleware('throttle:10|60,1')->group(function () {
3 //
4});

Also, you can have a DB field users.rate_limit and limit the amount for specific user:

1Route::middleware('auth:api', 'throttle:rate_limit,1')->group(function () {
2 Route::get('/user', function () {
3 //
4 });
5});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord