From 0695a8d128ba900a9b9388ada7a25fe8ea7b0401 Mon Sep 17 00:00:00 2001 From: Ahmed Alaa Date: Wed, 9 Apr 2025 18:13:00 +0200 Subject: [PATCH 1/2] Document the optional argument on database transactions --- database.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/database.md b/database.md index 14c9c68adb..88d15d238e 100644 --- a/database.md +++ b/database.md @@ -379,6 +379,22 @@ DB::transaction(function () { }); ``` +You may optionally pass a closure to the `transaction` method to be executed when the transaction fails: + +```php +use App\Notifications\SomethingImportantBroke; +use Illuminate\Support\Facades\DB; +use Illuminate\Support\Facades\Notification; + +DB::transaction(function () { + DB::update('update users set votes = 1'); + + DB::delete('delete from posts'); +}, onFailure: function () { + Notification::send($admin, new SomethingImportantBroke); +}); +``` + #### Handling Deadlocks From 324b1e61fc0ddf9887f3ed4fdda52b0d9948bfa8 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 15 Apr 2025 10:20:07 -0500 Subject: [PATCH 2/2] Update database.md --- database.md | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/database.md b/database.md index 88d15d238e..40f5a06b17 100644 --- a/database.md +++ b/database.md @@ -379,19 +379,17 @@ DB::transaction(function () { }); ``` -You may optionally pass a closure to the `transaction` method to be executed when the transaction fails: +You may optionally pass a closure to the `transaction` method that will be executed if the transaction fails: ```php -use App\Notifications\SomethingImportantBroke; use Illuminate\Support\Facades\DB; -use Illuminate\Support\Facades\Notification; DB::transaction(function () { DB::update('update users set votes = 1'); DB::delete('delete from posts'); }, onFailure: function () { - Notification::send($admin, new SomethingImportantBroke); + // ... }); ```