PHPackages                             larowka/prevent-duplicate-requests - 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. [API Development](/categories/api)
4. /
5. larowka/prevent-duplicate-requests

ActiveLibrary[API Development](/categories/api)

larowka/prevent-duplicate-requests
==================================

Prevent duplicate requests middleware for Laravel applications.

v1.2.0(11mo ago)02.1k↑100%1MITPHPPHP ^8.1CI passing

Since Jun 19Pushed 11mo ago1 watchersCompare

[ Source](https://github.com/larowka/prevent-duplicate-requests)[ Packagist](https://packagist.org/packages/larowka/prevent-duplicate-requests)[ Docs](https://github.com/larowka/prevent-duplicate-requests)[ RSS](/packages/larowka-prevent-duplicate-requests/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (3)Dependencies (5)Versions (5)Used By (1)

Prevent Duplicate Requests Middleware for Laravel
=================================================

[](#prevent-duplicate-requests-middleware-for-laravel)

[![Latest Version on Packagist](https://camo.githubusercontent.com/4ec78413327c3e09b6ed0836d9209898ea834ca2305fd4ddb54e53be94509ed4/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726f776b612f70726576656e742d6475706c69636174652d72657175657374732e737667)](https://packagist.org/packages/larowka/prevent-duplicate-requests)[![Total Downloads](https://camo.githubusercontent.com/7204871085ff176f2c01772bf422999df864d46845a081a7fbc079fd07096e3c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726f776b612f70726576656e742d6475706c69636174652d72657175657374732e737667)](https://packagist.org/packages/larowka/prevent-duplicate-requests)[![License: MIT](https://camo.githubusercontent.com/fdf2982b9f5d7489dcf44570e714e3a15fce6253e0cc6b5aa61a075aac2ff71b/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c6963656e73652d4d49542d79656c6c6f772e737667)](https://opensource.org/licenses/MIT)[![PHPUnit](https://github.com/larowka/prevent-duplicate-requests/actions/workflows/tests.yml/badge.svg)](https://github.com/larowka/prevent-duplicate-requests/actions/workflows/tests.yml)

Middleware for Laravel that prevents duplicate requests based on user actions.

This middleware is designed to manage and prevent duplicate requests within a specified timeframe, ensuring that only unique requests are processed.

- [Prevent Duplicate Requests Middleware for Laravel](#prevent-duplicate-requests-middleware-for-laravel)
    - [Installation](#installation)
    - [Usage](#usage)
        - [Laravel 11](#laravel-11)
            - [Global Middleware](#global-middleware)
            - [Assigning Middleware to Routes](#assigning-middleware-to-routes)
            - [Middleware Aliases](#middleware-aliases)
        - [Laravel 10](#laravel-10)
    - [Features](#features)
    - [Testing](#testing)
    - [Changelog](#changelog)
    - [Contributing](#contributing)
    - [Security](#security)
    - [Credits](#credits)
    - [License](#license)

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

[](#installation)

You can install the package via Composer:

```
composer require larowka/prevent-duplicate-requests
```

Usage
-----

[](#usage)

### Laravel 11

[](#laravel-11)

#### Global Middleware

[](#global-middleware)

To apply middleware globally to every HTTP request in Laravel 11, you can use the withMiddleware method in your bootstrap/app.php file:

```
use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests;

->withMiddleware(function ($middleware) {
    // ...
    $middleware->append(PreventDuplicateRequests::class);
});
```

#### Assigning Middleware to Routes

[](#assigning-middleware-to-routes)

If you want to assign middleware to specific routes, use the middleware method when defining the route:

```
Copy code
use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests;

Route::get('/example', function () {
    // Route logic...
})->middleware(PreventDuplicateRequests::class);
```

#### Middleware Aliases

[](#middleware-aliases)

You can define aliases for middleware in your bootstrap/app.php file to use shorter names for middleware classes:

```
use \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests;

->withMiddleware(function ($middleware) {
    $middleware->alias([
        'preventDuplicate' => PreventDuplicateRequests::class,
    ]);
});
```

Once defined, you can use the alias when assigning middleware to routes:

```
Route::get('/example', function () {
    // Route logic...
})->middleware('preventDuplicate');
```

### Laravel 10

[](#laravel-10)

Add the middleware to your Laravel application's HTTP kernel:

```
// app/Http/Kernel.php

protected $routeMiddleware = [
    // ...
    'preventDuplicate' => \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests::class,
];
```

Apply the middleware to your routes:

```
Route::middleware('preventDuplicate')->get('/example', function () {
    return 'Unique request handled.';
});
```

Or use globally:

```
// app/Http/Kernel.php

protected $middleware = [
    // ...
    \Larowka\PreventDuplicateRequests\Middleware\PreventDuplicateRequests::class,
];
```

Features
--------

[](#features)

- Prevents Duplicate Requests: Blocks duplicate requests within a specified timeframe.
- Flexible Configuration: Customize the duration for which requests are cached.
- Supports Authenticated Users: Differentiates between authenticated and unauthenticated users.
- Idempotency Support: Ensures idempotent actions are enforced for user-specific operations.

Testing
-------

[](#testing)

Run the tests using PHPUnit:

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

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

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security
--------

[](#security)

If you discover any security issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Serj Toropilin](https://github.com/larowka)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [LICENSE](LICENSE.md) for more information.

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance52

Moderate activity, may be stable

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~205 days

Total

3

Last Release

333d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ab33634a5e9af0cb56cfeb945d487121f1aacf4f635fee0c30a7b0d51fb85474?d=identicon)[larowka](/maintainers/larowka)

---

Top Contributors

[![larowka](https://avatars.githubusercontent.com/u/46128719?v=4)](https://github.com/larowka "larowka (6 commits)")

---

Tags

requestmiddlewareapilaravelconcurrentthrottleduplicate requests

###  Code Quality

TestsPHPUnit

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/larowka-prevent-duplicate-requests/health.svg)

```
[![Health](https://phpackages.com/badges/larowka-prevent-duplicate-requests/health.svg)](https://phpackages.com/packages/larowka-prevent-duplicate-requests)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[defstudio/telegraph

A laravel facade to interact with Telegram Bots

816333.8k3](/packages/defstudio-telegraph)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[essa/api-tool-kit

set of tools to build an api with laravel

53390.1k](/packages/essa-api-tool-kit)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[mtownsend/request-xml

The missing XML support for Laravel's Request class.

43488.4k](/packages/mtownsend-request-xml)

PHPackages © 2026

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