Я сделал код ниже для проверки транзакции, в которой баланс и история будут сохранены в базе данных или ни в одной из них.Однако, когда я запускаю код и проверяю базу данных, я вижу, что баланс все еще вставляется в банк, а не аннулируется.В чем может быть ошибка?
Ниже приведен код метода моей модели баланса, отвечающей за операцию
public function deposit(float $value) : Array {
DB::beginTransaction();
$totalBefore = null;
// $totalBefore = $this->amount ? $this->amount : 0;
$this->amount += number_format($value, 2, ".", '');
$deposit = $this->save();
$historic = auth()->user()->historics()->create([
'type' => 'I',
'amount' => $value,
'total_before' => $totalBefore,
'total_after' => $this->amount,
'date' => date('Ymd'),
]);
if ($deposit && $historic) {
DB::commit();
return [
'success' => true,
'message' => 'Sucesso ao recarregar!'
];
}
else {
DB::rollBack();
return [
'success' => false,
'message' => 'Falha ao recarregar!'
];
}
}