PHPackages                             aporat/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. aporat/laravel-rate-limiter

ActiveLibrary[Caching](/categories/caching)

aporat/laravel-rate-limiter
===========================

A flexible rate limiting middleware for Laravel and Lumen applications

v4.1.0(1y ago)41.5k↑150%MITPHPPHP ^8.4CI passing

Since Aug 24Pushed 1mo ago1 watchersCompare

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

READMEChangelog (4)Dependencies (6)Versions (6)Used By (0)

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

[](#laravel-rate-limiter)

[![Latest Stable Version](https://camo.githubusercontent.com/9a7a596b9a6bccd74bdd990908950eeee88613440793667a158a0663e7afc8ba/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f61706f7261742f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/aporat/laravel-rate-limiter)[![Downloads](https://camo.githubusercontent.com/1333aabdb2384b512e10ddc09233eb69f56e73a7756617ae72d6ffa92f612363/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f61706f7261742f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265266c6f676f3d636f6d706f736572)](https://packagist.org/packages/aporat/laravel-rate-limiter)[![Codecov](https://camo.githubusercontent.com/41cef126750e5c657106f82ec315150392a48440f7bc749a8936a626c414d5eb/68747470733a2f2f696d672e736869656c64732e696f2f636f6465636f762f632f6769746875622f61706f7261742f6c61726176656c2d726174652d6c696d697465723f7374796c653d666c61742d737175617265)](https://codecov.io/github/aporat/laravel-rate-limiter)[![Laravel Version](https://camo.githubusercontent.com/40236e2476ff414887c1d4654db9142ebac4bce19aac8cd02eb1c6d2762deb09/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c2d31332e782d6f72616e67652e7376673f7374796c653d666c61742d737175617265)](https://laravel.com/docs/13.x)[![GitHub Actions Workflow Status](https://camo.githubusercontent.com/f9c9c6ee5bf08b94f3ceec4158581a66687baeec1fb56624f53f1b169d024c35/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61706f7261742f6c61726176656c2d726174652d6c696d697465722f63692e796d6c3f7374796c653d666c61742d737175617265)](https://camo.githubusercontent.com/f9c9c6ee5bf08b94f3ceec4158581a66687baeec1fb56624f53f1b169d024c35/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f61706f7261742f6c61726176656c2d726174652d6c696d697465722f63692e796d6c3f7374796c653d666c61742d737175617265)[![License](https://camo.githubusercontent.com/67b3cc26e0f6ad01ea90d81bee3d4dc96b5ef964288519d15775430ee4a5d036/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f61706f7261742f6c61726176656c2d726174652d6c696d697465722e7376673f7374796c653d666c61742d737175617265)](https://github.com/aporat/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**: 12.x or 13.x
- **Redis**: Required for storage (ext-redis extension)
- **Composer**: Required for installation

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

[](#installation)

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

```
composer require aporat/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`:

```
'providers' => [
    // ...
    Aporat\RateLimiter\Laravel\RateLimiterServiceProvider::class,
],
```

Optionally, register the facade for cleaner syntax:

```
'aliases' => [
    // ...
    'RateLimiter' => \Aporat\RateLimiter\Facades\RateLimiter::class,
],
```

Publish the configuration file:

```
php artisan vendor:publish --provider="Aporat\RateLimiter\Laravel\RateLimiterServiceProvider" --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 = [
    // ...
    \Aporat\RateLimiter\Laravel\Middleware\RateLimit::class,
];
```

Or apply it to specific routes:

```
Route::get('/api/test', function () {
    return 'Hello World';
})->middleware('Aporat\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 Aporat\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/aporat/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/aporat/laravel-rate-limiter/issues)
- **Source**: [GitHub Repository](https://github.com/aporat/laravel-rate-limiter)

###  Health Score

49

—

FairBetter than 95% of packages

Maintenance70

Regular maintenance activity

Popularity23

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity76

Established project with proven stability

 Bus Factor1

Top contributor holds 78.7% of commits — single point of failure

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 ~562 days

Total

4

Last Release

401d ago

Major Versions

v1.0.0 → v3.0.02025-02-05

v3.0.0 → v4.0.02025-02-22

PHP version history (3 changes)v1.0.0PHP ^7.4

v3.0.0PHP ^8.2

v4.1.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/54592564aa6e76cb00fdb16a8b7fadaea333de11da7fd8a739fe4812237a551c?d=identicon)[aporat](/maintainers/aporat)

---

Top Contributors

[![aporat](https://avatars.githubusercontent.com/u/415576?v=4)](https://github.com/aporat "aporat (48 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (7 commits)")[![claude](https://avatars.githubusercontent.com/u/81847?v=4)](https://github.com/claude "claude (3 commits)")[![StyleCIBot](https://avatars.githubusercontent.com/u/11048387?v=4)](https://github.com/StyleCIBot "StyleCIBot (3 commits)")

---

Tags

middlewarelaravellumenredisrate-limiterthrottlerate limiting

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

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

```
[![Health](https://phpackages.com/badges/aporat-laravel-rate-limiter/health.svg)](https://phpackages.com/packages/aporat-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)
