Skip to content

Commit 6f57ce6

Browse files
committed
added tip #353
1 parent bd7ee03 commit 6f57ce6

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Daily Laravel/PHP tips I share on my [X](https://x.com/OussamaMater) and [Linked
1010
Currently, there are over 300 tips categorized as follows:
1111

1212
- 🗄️ [Eloquent & Database Tips](./tips/eloquent-and-database.md) (98 tips)
13-
- 🛠️ [Helpers Tips](./tips/helpers.md) (66 tips)
13+
- 🛠️ [Helpers Tips](./tips/helpers.md) (67 tips)
1414
- 🧪 [Testing Tips](./tips/testing.md) (29 tips)
1515
- 💻 [Artisan & Console Command Tips](./tips/console.md) (26 tips)
1616
- 🔄 [Routing & Request Tips](./tips/routing.md) (23 tips)

tips/helpers.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
- [Clamp Numbers](#laravel-tip--clamp-numbers-️)
6666
- [Date Checks with Carbon](#laravel-tip--date-checks-with-carbon-️)
6767
- [Handle Pluralization Elegantly](#laravel-tip--handle-pluralization-elegantly-️)
68+
- [Wrap a Pipeline in a DB Transaction Elegantly](#laravel-tip--wrap-a-pipeline-in-a-db-transaction-elegantly-️)
6869

6970
## Laravel Tip 💡: The "squish" method ([⬆️](#helpers-tips-cd-))
7071

@@ -1238,3 +1239,22 @@ trans_choice('messages.count', 10); // "10 comments"
12381239
// Yes, you also get messages depending on the set locale 🔥
12391240
// Another bonus: No more ugly if statements 🔥
12401241
```
1242+
1243+
## Laravel Tip 💡: Wrap a Pipeline in a DB Transaction Elegantly ([⬆️](#helpers-tips-cd-))
1244+
1245+
If you are using Laravel pipelines and wrapping the whole thing in a DB transaction, since Laravel v12.22 you can simplify your code by just calling "withinTransaction()" on the pipeline 🚀
1246+
1247+
```diff
1248+
<?php
1249+
1250+
- DB::transaction(function () {
1251+
$user = Pipeline::send($user)
1252+
+ ->withinTransaction()
1253+
->through([
1254+
ProcessOrder::class,
1255+
TransferFunds::class,
1256+
UpdateInventory::class,
1257+
])
1258+
- ->thenReturn();
1259+
});
1260+
```

0 commit comments

Comments
 (0)