Skip to content

Commit e98ac6b

Browse files
[12.x] Document the optional argument on database transactions (#10321)
* Document the optional argument on database transactions * Update database.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 9f8f242 commit e98ac6b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

database.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,20 @@ DB::transaction(function () {
379379
});
380380
```
381381

382+
You may optionally pass a closure to the `transaction` method that will be executed if the transaction fails:
383+
384+
```php
385+
use Illuminate\Support\Facades\DB;
386+
387+
DB::transaction(function () {
388+
DB::update('update users set votes = 1');
389+
390+
DB::delete('delete from posts');
391+
}, onFailure: function () {
392+
// ...
393+
});
394+
```
395+
382396
<a name="handling-deadlocks"></a>
383397
#### Handling Deadlocks
384398

0 commit comments

Comments
 (0)