定制 larowka/prevent-duplicate-requests 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

larowka/prevent-duplicate-requests

最新稳定版本:v1.2.0

Composer 安装命令:

composer require larowka/prevent-duplicate-requests

包简介

Prevent duplicate requests middleware for Laravel applications.

README 文档

README

Latest Version on Packagist Total Downloads License: MIT PHPUnit

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.

Installation

You can install the package via Composer:

composer require larowka/prevent-duplicate-requests

Usage

Laravel 11

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

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

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

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

  • 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

Run the tests using PHPUnit:

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

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

Credits

License

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

统计信息

  • 总下载量: 1.5k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-06-19