File tree Expand file tree Collapse file tree
user_guide_src/source/database/transactions Expand file tree Collapse file tree Original file line number Diff line number Diff line change 44
55$ orderId = $ this ->db ->transaction (static function ($ db ) use ($ order ): int {
66 $ db ->table ('orders ' )->insert ($ order );
7- $ orderId = $ db ->insertID ();
7+ $ insertedOrderId = $ db ->insertID ();
88
9- $ db ->afterCommit (static function () use ($ orderId ): void {
9+ $ db ->afterCommit (static function () use ($ insertedOrderId ): void {
1010 service ('cache ' )->delete ('orders_list ' );
11- Events::trigger ('order_created ' , $ orderId );
11+ Events::trigger ('order_created ' , $ insertedOrderId );
1212
1313 // Dispatch a queued job or send a notification here.
1414 // The new order is committed and visible to other database connections.
1515 });
1616
17- return $ orderId ;
17+ return $ insertedOrderId ;
1818});
19+
20+ if ($ orderId === false ) {
21+ // Handle the transaction failure.
22+ }
You can’t perform that action at this time.
0 commit comments