diff --git a/database.md b/database.md index 14c9c68adb..40f5a06b17 100644 --- a/database.md +++ b/database.md @@ -379,6 +379,20 @@ DB::transaction(function () { }); ``` +You may optionally pass a closure to the `transaction` method that will be executed if the transaction fails: + +```php +use Illuminate\Support\Facades\DB; + +DB::transaction(function () { + DB::update('update users set votes = 1'); + + DB::delete('delete from posts'); +}, onFailure: function () { + // ... +}); +``` + #### Handling Deadlocks