PHPackages                             amiiiiink/laravel-rate-limiter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Caching](/categories/caching)
4. /
5. amiiiiink/laravel-rate-limiter

ActiveLibrary[Caching](/categories/caching)

amiiiiink/laravel-rate-limiter
==============================

A flexible rate limiting middleware for Laravel and Lumen applications

v1.0.2(9mo ago)14[2 PRs](https://github.com/amiiiiink/laravel12-rate-limiter/pulls)MITPHPPHP ^8.4CI passing

Since Aug 4Pushed 5mo agoCompare

[ Source](https://github.com/amiiiiink/laravel12-rate-limiter)[ Packagist](https://packagist.org/packages/amiiiiink/laravel-rate-limiter)[ Docs](https://github.com/amiiiiink/laravel-rate-limiter)[ GitHub Sponsors](https://github.com/amiiiiink)[ RSS](/packages/amiiiiink-laravel-rate-limiter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (7)Versions (6)Used By (0)

Laravel Rate Limiter
====================

[](#laravel-rate-limiter)

[![Latest Stable Version](https://camo.githubusercontent.com/e59f433cbe9c87ef1a63e37a72121bd6835f338156c7f1d300c421167caec7db/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/amiiiiink/laravel-rate-limiter)[![Downloads](https://camo.githubusercontent.com/4ecceb38f7d084c6c5e7fb7ccf64de584c3c135297b494239f8031b07b460e91/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/amiiiiink/laravel-rate-limiter)[![Codecov](https://camo.githubusercontent.com/865974e1edc61522f3e4d829a415900426ce2c868ef7cd160abfc6b15a43bac5/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465723f7374796c653d666c61742d737175617265)](https://codecov.io/github/amiiiiink/laravel-rate-limiter)[![Laravel Version](https://camo.githubusercontent.com/3ccc671eca69e8695910518f858e08d1f046a75884b69d4821d3ccfcfee3db83/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31322e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/docs/12.x)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/a4fe3cea761b9638fb3eb677d05b22a8887f32128666808b2f056ff8bb5c524c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465722f63692e796d6c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/a4fe3cea761b9638fb3eb677d05b22a8887f32128666808b2f056ff8bb5c524c/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465722f63692e796d6c3f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/d80d33f82649c2b2881f71174f7090ef64193134b05a7906ae50b92862d9a14e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f616d69696969696e6b2f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/amiiiiink/laravel-rate-limiter/blob/master/LICENSE)

A flexible rate limiting middleware for Laravel applications, designed to throttle requests and actions using Redis.

Features
--------

[](#features)

- Configurable rate limits per hour, minute, and second.
- Flexible limiting by IP, user ID, request method, and custom tags.
- IP blocking for abuse prevention.
- Optional rate limit headers in responses.
- Redis-backed storage for scalability.

Requirements
------------

[](#requirements)

- **PHP**: 8.4 or higher
- **Laravel**: 10.x, 11.x or 12.x
- **Redis**: Required for storage (ext-redis extension)
- **Composer**: Required for installation

Installation
------------

[](#installation)

Install the package via [Composer](https://getcomposer.org/):

```
composer require amiiiiink/laravel-rate-limiter
```

The service provider (`RateLimiterServiceProvider`) is automatically registered via Laravel’s package discovery. If auto-discovery is disabled, add it to `config/app.php`:

Publish the configuration file:

```
php artisan vendor:publish --tag=config
```

This copies `rate-limiter.php` to your `config/` directory.

Configuration
-------------

[](#configuration)

Edit `config/rate-limiter.php` to adjust limits and Redis settings:

```
return [
    'limits' => [
        'hourly' => 3000,
        'minute' => 60,
        'second' => 10,
    ],
    'log_errors' => true, // Set to false to disable logging of rate limit violations
    'redis' => [
        'host' => env('RATE_LIMITER_REDIS_HOST', '127.0.0.1'),
        'port' => env('RATE_LIMITER_REDIS_PORT', 6379),
        'database' => env('RATE_LIMITER_REDIS_DB', 0),
        'prefix' => env('RATE_LIMITER_REDIS_PREFIX', 'rate-limiter:'),
    ],
];
```

Add these to your `.env` file if needed:

```
RATE_LIMITER_REDIS_HOST=127.0.0.1
RATE_LIMITER_REDIS_PORT=6379
RATE_LIMITER_REDIS_DB=0
RATE_LIMITER_REDIS_PREFIX=rate-limiter:

```

Usage
-----

[](#usage)

### Middleware

[](#middleware)

Apply rate limiting globally by registering the middleware in `app/Http/Kernel.php`:

```
protected $middleware = [
    // ...
    \amiiiiink\RateLimiter\Laravel\Middleware\RateLimit::class,
];
```

Or apply it to specific routes:

```
Route::get('/api/test', function () {
    return 'Hello World';
})->middleware('amiiiiink\RateLimiter\Laravel\Middleware\RateLimit');
```

The middleware uses the configured limits (`hourly`, `minute`, `second`) and exempts IPs starting with `10.0.`.

### Manual Rate Limiting

[](#manual-rate-limiting)

Use the `RateLimiter` facade for custom limiting:

```
use amiiiiink\RateLimiter\Laravel\Facades\RateLimiter;

Route::post('/submit', function (Request $request) {
    RateLimiter::create($request)
        ->withUserId(auth()->id() ?? 'guest')
        ->withName('form_submission')
        ->withTimeInterval(3600)
        ->limit(5); // 5 submissions per hour

    return 'Submitted!';
});
```

### IP Blocking

[](#ip-blocking)

Block an IP manually:

```
RateLimiter::blockIpAddress('192.168.1.1', 86400); // Block for 24 hours
```

Check if an IP is blocked:

```
if (RateLimiter::isIpAddressBlocked()) {
    abort(403, 'Your IP is blocked.');
}
```

### Rate Limit Headers

[](#rate-limit-headers)

Add headers to responses:

```
$response = new Response('OK');
RateLimiter::create($request)
    ->withResponse($response)
    ->withRateLimitHeaders()
    ->limit(100);

return $response; // Includes X-Rate-Limit-Limit and X-Rate-Limit-Remaining
```

Testing
-------

[](#testing)

Run the test suite:

```
composer test
```

Generate coverage reports:

```
composer test-coverage
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please:

1. Fork the repository.
2. Create a feature branch (`git checkout -b feature/new-feature`).
3. Commit your changes (`git commit -m "Add new feature"`).
4. Push to the branch (`git push origin feature/new-feature`).
5. Open a pull request.

Report issues at [GitHub Issues](https://github.com/amiiiiink/laravel-rate-limiter/issues).

License
-------

[](#license)

This package is licensed under the [MIT License](LICENSE). See the [License File](LICENSE) for details.

Support
-------

[](#support)

- **Issues**: [GitHub Issues](https://github.com/amiiiiink/laravel-rate-limiter/issues)
- **Source**: [GitHub Repository](https://github.com/amiiiiink/laravel-rate-limiter)

###  Health Score

35

—

LowBetter than 79% of packages

Maintenance66

Regular maintenance activity

Popularity5

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

3

Last Release

281d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/9a68762ff9849034c7fab30540619ae9cb41f0af9ee4fc9f57c6498517387eec?d=identicon)[amiiiiink](/maintainers/amiiiiink)

---

Tags

middlewarelaravellumenredisrate-limiterthrottlerate limiting

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/amiiiiink-laravel-rate-limiter/health.svg)

```
[![Health](https://phpackages.com/badges/amiiiiink-laravel-rate-limiter/health.svg)](https://phpackages.com/packages/amiiiiink-laravel-rate-limiter)
```

###  Alternatives

[spatie/laravel-responsecache

Speed up a Laravel application by caching the entire response

2.8k8.2M51](/packages/spatie-laravel-responsecache)[monospice/laravel-redis-sentinel-drivers

Redis Sentinel integration for Laravel and Lumen.

103830.5k](/packages/monospice-laravel-redis-sentinel-drivers)[namoshek/laravel-redis-sentinel

An extension of Laravels Redis driver which supports connecting to a Redis master through Redis Sentinel.

38679.0k](/packages/namoshek-laravel-redis-sentinel)[ginnerpeace/laravel-redis-lock

Simple redis distributed locks for Laravel.

15114.4k](/packages/ginnerpeace-laravel-redis-lock)[yangusik/laravel-balanced-queue

Laravel queue management with load balancing between partitions (user groups)

786.4k](/packages/yangusik-laravel-balanced-queue)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
