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

PhpLaravelLaravel 4Eloquent

Php Problem Overview


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?

Php Solutions


Solution 1 - Php

To also get soft deleted models

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

Only soft deleted models in your results

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

Solution 2 - Php

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiontotymedliView Question on Stackoverflow
Solution 1 - PhpmarcanuyView Answer on Stackoverflow
Solution 2 - PhpkushView Answer on Stackoverflow