To get all rows from a table, I have to use Model::all()
but (from good reason) this doesn't gives me back the soft deleted rows. Is there a way I can accomplish this with Eloquent?
Asked
Active
Viewed 1.3e+01k times
2 Answers
263
To also get soft deleted models
$trashedAndNotTrashed = Model::withTrashed()->get();
Only soft deleted models in your results
$onlySoftDeleted = Model::onlyTrashed()->get();

marcanuy
- 23,118
- 9
- 64
- 113
-
2Link to the docs: http://laravel.com/docs/5.1/eloquent#querying-soft-deleted-models – user Dec 02 '15 at 21:47
-
Great!!! https://itsolutionstuff.com/post/how-to-get-soft-deleted-records-in-laravel-5example.html – Kamlesh Feb 05 '19 at 14:52
-
How can I include trashed items from relation items? – Čamo Dec 05 '20 at 23:42
19
Use this to get all record
Model::withTrashed()->get();
Use this to get record of particular id
Property::withTrashed()->find($list->property_id);
or
// 1 is unique id of the table
Model::withTrashed()->find(1);
-
7The first part of this answer was already posted. The second part has nothing to do with the question, it is just common Eloquent usage... – totymedli Oct 16 '18 at 20:50