laravel 事务不提交 不知道哪里写错了

laravel 事务不提交 不知道哪里写错了

以下是代码
DB::transaction(function () use ($payment,$userBalance) {

            Payment::insert($payment);
            $userName = $payment['payment_user_name'];
            User::where('user_name', $userName)
                 ->increment('user_balance', $userBalance);
        });
        
        
        跪求指教
阅读 4.8k
2 个回答
DB::transaction(function () use ($payment,$userBalance) {
         try {
            Payment::insert($payment);
            $userName = $payment['payment_user_name'];
            User::where('user_name', $userName)->increment('user_balance', $userBalance);
         } catch (\Exception $e) {
            var_dump($e);
            exit;
         }
});
//打印输出下sql 看是否有问题,因为在 transaction 闭包若抛出任何异常会导致事务自动回滚
\DB::listen(function ($sql,$bind) { 
   dump($sql,$bind);
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进