如何从 Laravel 的表中获取所有行(也软删除)?

2022-01-08 00:00:00 php laravel laravel-4 eloquent

要从表中获取所有行,我必须使用 Model::all() 但是(有充分理由)这不会让我恢复软删除的行.有没有办法用 Eloquent 实现这一点?

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?

推荐答案

同时获取软删除模型

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

您的结果中仅软删除模型

Only soft deleted models in your results

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

相关文章