PHP code example of adilazhari / laravel-idempotency
1. Go to this page and download the library: Download adilazhari/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/ */
adilazhari / laravel-idempotency example snippets
use AdilAzhari\LaravelIdempotency\Http\Middleware\IdempotencyMiddleware;
use Illuminate\Support\Facades\Route;
Route::post('/payments', CreatePaymentController::class)
->middleware(IdempotencyMiddleware::class);
use AdilAzhari\LaravelIdempotency\Queue\Middleware\JobIdempotencyMiddleware;
final class ChargeCustomer implements ShouldQueue
{
public function __construct(
private readonly Order $order,
) {}
public function middleware(): array
{
return [new JobIdempotencyMiddleware(key: $this->order->id)];
}
public function handle(): void
{
// Charge the customer. If this job is retried or redelivered with
// the same key and the same payload, handle() will not run again.
}
}
use AdilAzhari\LaravelIdempotency\Support\IdempotencyContext;
public function middleware(): array
{
return [new JobIdempotencyMiddleware(
key: IdempotencyContext::current() ?? $this->order->id
)];
}