Idempotency-Key header (RFC 3265), ensuring compatibility with client libraries (e.g., Stripe, PayPal) and industry best practices.Illuminate\Http\Request), reducing friction in adoption.IdempotencyKey::validate()).idempotency_keys table), or custom drivers.Http::post() calls that include the Idempotency-Key header.actingAs(), json()) for seamless test coverage./webhooks/stripe, /payments/capture).curl --retry 3).IdempotencyKey::setTTL(3600) for orders).idempotency.hits counter).Idempotency-Key header.composer require webrek/laravel-idempotency
Publish config if customizing storage/TTL:
php artisan vendor:publish --tag="idempotency-config"
app/Http/Kernel.php or apply per-route:
Route::post('/orders', [OrderController::class, 'store'])
->middleware('idempotency:orders'); // Optional: namespace keys
.env (e.g., IDEMPOTENCY_DRIVER=redis) or override in config/idempotency.php.Idempotency-Key: uuid4()
IdempotencyKey::log($key, $request->id());
idempotency:fallback middleware for storage failures (e.g., log and proceed).user_123_* for user-specific requests).| Failure | Impact | Mitigation |
|---|---|---|
| Storage unavailability | Retries fail silently | Fallback to logging + retry logic |
| Key collisions | Race conditions in stateful ops | Enforce strong key generation |
| Malformed headers | Invalid requests slip through | Validate Idempotency-Key in middleware |
| TTL too short/long | False positives/negatives | Benchmark TTLs per use case |
sleep(3601); retry() should fail).How can I help you explore Laravel packages today?