Laravel rate limit API routes with throttle middleware
PHP Dasun Kalupahana 110 views
<?php
// routes/api.php: 60 requests per minute
Route::middleware('throttle:60,1')->group(function () {
Route::get('/posts', [PostController::class, 'index']);
});
// Custom limiter in AppServiceProvider::boot()
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
RateLimiter::for('login', function (Request $request) {
return Limit::perMinute(5)->by($request->ip());
});
// Apply it
Route::post('/login', LoginController::class)->middleware('throttle:login');
Limits how many requests a client can make per minute and returns a 429 when exceeded. Use it on login, API and public endpoints to stop abuse.
Learn more on the blog
MySQL
PostgreSQL vs MySQL Performance: Real Benchmarks Compared
Last updated: 7 November 2026. See the update log at the end."Which...
8 min read
Laravel
Secure a Laravel App Before Production: Tested Checklist
Last updated: 8 November 2026. See the update log at the end.Laravel...
12 min read
PHP
How to Detect and Fix PHP Memory Leaks
Last updated: 5 November 2026. See the update log at the end.In...
9 min read