1. Go to this page and download the library: Download truschery/idem 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/ */
use Truschery\Idem\Middleware\EnsureIdempotent;
class ProcessPaymentJob implements ShouldQueue
{
public function __construct(private string $paymentId) {}
public function middleware(): array
{
return [new EnsureIdempotent($this->paymentId)];
}
public function handle(): void
{
// Runs only once, even if the job is dispatched multiple times
Payment::process($this->paymentId);
}
}
use Truschery\Idem\Once;
$result = Once::do('send-welcome-email:' . $user->id, function () use ($user) {
return Mail::to($user)->send(new WelcomeMail($user));
});