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

浪子不回头ぞ 提交于 2020-04-07 16:57:35

问题


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?


回答1:


To also get soft deleted models

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

Only soft deleted models in your results

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



回答2:


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


来源:https://stackoverflow.com/questions/20474439/how-to-get-all-rows-soft-deleted-too-from-a-table-in-laravel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!