File tree 2 files changed +18
-1
lines changed
2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ Daily Laravel/PHP tips I share on my [X](https://x.com/OussamaMater) and [Linked
9
9
10
10
Currently, there are over 300 tips categorized as follows:
11
11
12
- - 🗄️ [ Eloquent & Database Tips] ( ./tips/eloquent-and-database.md ) (94 tips)
12
+ - 🗄️ [ Eloquent & Database Tips] ( ./tips/eloquent-and-database.md ) (95 tips)
13
13
- 🛠️ [ Helpers Tips] ( ./tips/helpers.md ) (61 tips)
14
14
- 🧪 [ Testing Tips] ( ./tips/testing.md ) (27 tips)
15
15
- 💻 [ Artisan & Console Command Tips] ( ./tips/console.md ) (25 tips)
Original file line number Diff line number Diff line change 94
94
- [ The New "incrementOrCreate" Method] ( #laravel-tip--the-new-incrementorcreate-method-️ )
95
95
- [ Keep an Eye on Open Connections] ( #laravel-tip--keep-an-eye-on-open-connections-️ )
96
96
- [ The "MassPrunable" trait] ( #laravel-tip--the-massprunable-trait-️ )
97
+ - [ Restore Trashed Models] ( #laravel-tip--restore-trashed-models-️ )
97
98
98
99
## Laravel Tip 💡: Get Original Attributes ([ ⬆️] ( #eloquent--database-tips-cd- ) )
99
100
@@ -1906,3 +1907,19 @@ class Flight extends Model
1906
1907
// Schedule the pruning command to run daily for example
1907
1908
$schedule->command(PruneCommand::class)->daily();
1908
1909
```
1910
+
1911
+ ## Laravel Tip 💡: Restore Trashed Models ([ ⬆️] ( #eloquent--database-tips-cd- ) )
1912
+
1913
+ Have you ever needed to restore trashed models? While you could do this manually, Laravel ships with a restore method for exactly this 🚀
1914
+
1915
+ ``` php
1916
+ <?php
1917
+
1918
+ Flight::query()
1919
+ ->onlyTrashed() // Only the trashed records will be targeted
1920
+ ->where('airline_id', 1)
1921
+ // ->update(['deleted_at' => null]) Instead of this
1922
+ ->restore(); // You can do this 🔥
1923
+
1924
+ // Restores all trashed records matching the condition with a single query 🔥
1925
+ ```
You can’t perform that action at this time.
0 commit comments