ChatGPT解决这个技术问题 Extra ChatGPT

How to get all rows (soft deleted too) from a table in Laravel?

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?


m
marcanuy

To also get soft deleted models

$trashedAndNotTrashed = Model::withTrashed()->get();

Only soft deleted models in your results

$onlySoftDeleted = Model::onlyTrashed()->get();

How can I include trashed items from relation items?
R
Robert

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);

The first part of this answer was already posted. The second part has nothing to do with the question, it is just common Eloquent usage...