Laravel

Laravel Rate Limiting: Protect Your Application

January 16, 2026 1 min read 62 views

Protect your app with rate limiting:

Define Rate Limiters

RateLimiter::for('api', function (Request $request) {
    return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
});

Custom Response

RateLimiter::for('uploads', function (Request $request) {
    return Limit::perMinute(5)
        ->by($request->user()->id)
        ->response(fn() => response('Too many uploads!', 429));
});

Apply to Routes

Route::middleware(['throttle:api'])->group(function () {
    // Protected routes
});
Share this post:

Related Posts

Comments (0)

Please log in to leave a comment. Log in

No comments yet. Be the first to comment!