Skip to content

Commit e89a530

Browse files
committed
added tip #329
1 parent 231e526 commit e89a530

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Daily Laravel/PHP tips I share on my [X](https://x.com/OussamaMater) and [Linked
99

1010
Currently, there are over 300 tips categorized as follows:
1111

12-
- 🗄️ [Eloquent & Database Tips](./tips/eloquent-and-database.md) (94 tips)
12+
- 🗄️ [Eloquent & Database Tips](./tips/eloquent-and-database.md) (95 tips)
1313
- 🛠️ [Helpers Tips](./tips/helpers.md) (61 tips)
1414
- 🧪 [Testing Tips](./tips/testing.md) (27 tips)
1515
- 💻 [Artisan & Console Command Tips](./tips/console.md) (25 tips)

tips/eloquent-and-database.md

+17
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
- [The New "incrementOrCreate" Method](#laravel-tip--the-new-incrementorcreate-method-️)
9595
- [Keep an Eye on Open Connections](#laravel-tip--keep-an-eye-on-open-connections-️)
9696
- [The "MassPrunable" trait](#laravel-tip--the-massprunable-trait-️)
97+
- [Restore Trashed Models](#laravel-tip--restore-trashed-models-️)
9798

9899
## Laravel Tip 💡: Get Original Attributes ([⬆️](#eloquent--database-tips-cd-))
99100

@@ -1906,3 +1907,19 @@ class Flight extends Model
19061907
// Schedule the pruning command to run daily for example
19071908
$schedule->command(PruneCommand::class)->daily();
19081909
```
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+
```

0 commit comments

Comments
 (0)