Here is my code:
DB::transaction(function () use ($r, $certificate, $candidate) {
UserCertificate::create([
'user_id' => $r['user_id'],
'certificate_id' => $certificate->id,
'issue_date' => Carbon::now()
]);
// create badge
$this->createCandidateBadge($candidate, $certificate);
});
An exception happens while creating the candidate badge: $this->createCandidateBadge
But when I see user_certificates
table there is a certificate created! I don't want to create a certificate in DB unless a badge created successfully!