PHPackages                             chenpkg/laravel-idempotent - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. chenpkg/laravel-idempotent

ActiveLibrary[HTTP &amp; Networking](/categories/http)

chenpkg/laravel-idempotent
==========================

laravel idempotent middleware

1.1.1(4y ago)22.3k1MITPHPPHP ^7.0|^8.0

Since Aug 23Pushed 4y ago1 watchersCompare

[ Source](https://github.com/chenpkg/laravel-idempotent)[ Packagist](https://packagist.org/packages/chenpkg/laravel-idempotent)[ RSS](/packages/chenpkg-laravel-idempotent/feed)WikiDiscussions master Synced 4d ago

READMEChangelog (9)Dependencies (1)Versions (10)Used By (0)

 Idempotent
============

[](#-idempotent-)

 laravel 幂等中间件，防止客户端同一时间请求多次。

建议将 laravel 默认缓存设置为 redis，将得到更好的性能。

Requirement
-----------

[](#requirement)

1. PHP &gt;= 7.0 | PHP &gt;= 8.0
2. laravel &gt;= 6

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

[](#installation)

```
$ composer require chenpkg/laravel-idempotent
```

Usage
-----

[](#usage)

发布配置文件

```
$ php artisan vendor:publish --tag="laravel-idempotent"
```

中间件为 `Chenpkg\Idempotent\IdempotentMiddleware`，别名 `idempotent`

```
Route::group(['middleware' => 'idempotent'], function () {
    //...
});
```

> 注：请不要直接加在 `App\Http\Kernel` 的 `middleware` 里面，由于中间件执行顺序问题，可能导致该组件获取不到当前用户身份标识符 ID

或者你可以将它加入到指定路由中间件组中

```
protected $middlewareGroups = [
    // ...
    'api' => [
        'idempotent',
        'throttle:api',
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],
];
```

重复的请求将会抛出 `Chenpkg\Idempotent\Exceptions\RepeatRequestException` `Http` 异常

Configure
---------

[](#configure)

```
// config/idempotent.php

return [
    // true 自动获取唯一key, false 前端提供
    'forcible' => true,

    // 需要过滤重复请求的请求类型
    'methods' => ['POST', 'PUT', 'PATCH'],

    // 缓存有效时间/秒，防止死锁
    'seconds' => 10,

    // 获取当前用户
    'resolve_user' => function (\Illuminate\Http\Request $request) {
        return auth()->user();
    },

    // 前端提供 key 请求头名称.
    'header_name' => 'Idempotent-Key',
];
```

License
-------

[](#license)

MIT

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

Established project with proven stability

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

Recently: every ~48 days

Total

9

Last Release

1532d ago

Major Versions

0.0.4 → 1.0.02021-08-23

### Community

Maintainers

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

---

Top Contributors

[![chenpkg](https://avatars.githubusercontent.com/u/35981471?v=4)](https://github.com/chenpkg "chenpkg (11 commits)")

### Embed Badge

![Health badge](/badges/chenpkg-laravel-idempotent/health.svg)

```
[![Health](https://phpackages.com/badges/chenpkg-laravel-idempotent/health.svg)](https://phpackages.com/packages/chenpkg-laravel-idempotent)
```

###  Alternatives

[binaryk/laravel-restify

Laravel REST API helpers

651399.1k](/packages/binaryk-laravel-restify)[namu/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

54324.5k](/packages/namu-wirechat)[lomkit/laravel-rest-api

A package to build quick and robust rest api for the Laravel framework.

59152.2k](/packages/lomkit-laravel-rest-api)[wirechat/wirechat

A Laravel Livewire messaging app for teams with private chats and group conversations.

5434.7k](/packages/wirechat-wirechat)[api-platform/laravel

API Platform support for Laravel

59126.4k6](/packages/api-platform-laravel)[georgeboot/laravel-echo-api-gateway

Use Laravel Echo with API Gateway Websockets

10435.5k](/packages/georgeboot-laravel-echo-api-gateway)

PHPackages © 2026

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