PHP code example of bahadovic / laravel-idempotency
1. Go to this page and download the library: Download bahadovic/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/ */
bahadovic / laravel-idempotency example snippets
use Bahadovic\Idempotency\Events\IdempotencyResponseReplayed;
use Illuminate\Support\Facades\Event;
Event::listen(IdempotencyResponseReplayed::class, function ($event) {
logger()->info("Replayed cached response for key: {$event->key->value}");
});
use App\Http\Controllers\PaymentController;
use Illuminate\Support\Facades\Route;
Route::post('/api/payments', [PaymentController::class, 'charge'])
->middleware('idempotency');
use Bahadovic\Idempotency\Facades\Idempotency;
use Illuminate\Http\Request;
public function store(Request $request)
{
return Idempotency::process($request->toIdempotencyRequest(), function () {
// Business logic here
return response()->json(['status' => 'Charged']);
});
}