DB::beginTransaction();
try {
$exam = Exam::createForSubject($validated['subject_id'], $organization, $validated['name'], $validated['code']);
$exam->update($validated);
DB::commit(); // ✅ Commit only if everything succeeds
} catch (\Exception $e) {
DB::rollBack(); // ❌ Rollback on error
throw $e; // Optionally rethrow the error
}