PHP code example of wendelladriel / laravel-idempotency

1. Go to this page and download the library: Download wendelladriel/laravel-idempotency library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wendelladriel / laravel-idempotency example snippets


use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use WendellAdriel\Idempotency\Http\Middleware\Idempotent;

Route::post('/orders', function (Request $request) {
    return response()->json([
        'id' => 1,
        'item' => $request->input('item'),
    ], 201);
})->middleware(Idempotent::class);

use WendellAdriel\Idempotency\Enums\IdempotencyScope;
use WendellAdriel\Idempotency\Http\Middleware\Idempotent;

Route::post('/payments', ChargePaymentController::class)->middleware(
    Idempotent::using(
        ttl: 600,
        

Route::post('/orders', StoreOrderController::class)->middleware('idempotent');

use Symfony\Component\HttpFoundation\Response;
use WendellAdriel\Idempotency\Attributes\Idempotent;

#[Idempotent]
class OrderController
{
    public function store(): Response
    {
        // ...
    }
}

use WendellAdriel\Idempotency\Idempotency;

$key = Idempotency::key();
bash
php artisan vendor:publish --tag="idempotency"
bash
php artisan idempotency:list
php artisan idempotency:forget --key=checkout-1 --force