search

Home  >  Q&A  >  body text

transaction - laravel transaction does not commit. I don’t know where I wrote it wrong.

laravel transaction is not committed. I don’t know where I wrote it wrong

The following is the code
DB::transaction(function () use ($payment,$userBalance) {

            Payment::insert($payment);
            $userName = $payment['payment_user_name'];
            User::where('user_name', $userName)
                 ->increment('user_balance', $userBalance);
        });
        
        
        跪求指教
PHP中文网PHP中文网2808 days ago430

reply all(2)I'll reply

  • 高洛峰

    高洛峰2017-05-16 16:51:04

    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;
             }
    });

    reply
    0
  • 怪我咯

    怪我咯2017-05-16 16:51:04

    //打印输出下sql 看是否有问题,因为在 transaction 闭包若抛出任何异常会导致事务自动回滚
    \DB::listen(function ($sql,$bind) { 
       dump($sql,$bind);
    }

    reply
    0
  • Cancelreply