php 如何从 Laravel 的表中获取所有行(也被软删除)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20474439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get all rows (soft deleted too) from a table in Laravel?
提问by totymedli
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?
要从表中获取所有行,我必须使用Model::all()但是(有充分的理由)这不会让我返回软删除的行。有没有办法用 Eloquent 来完成这个任务?
回答by marcanuy
To also get soft deleted models
还可以获取软删除模型
$trashedAndNotTrashed = Model::withTrashed()->get();
Only soft deleted models in your results
结果中仅软删除模型
$onlySoftDeleted = Model::onlyTrashed()->get();
回答by kush
Use this to get all record
使用它来获取所有记录
Model::withTrashed()->get();
Use this to get record of particular id
使用它来获取特定 id 的记录
Property::withTrashed()->find($list->property_id);
or
// 1 is unique id of the table
// 1 是表的唯一 id
Model::withTrashed()->find(1);

