How to show soft deleted items in laravel?

Member

by adan , in category: PHP Frameworks , 17 days ago

How to show soft deleted items in laravel?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by wilmer.lemke , 16 days ago

@adan 

In Laravel, soft deleted items can be retrieved by using the withTrashed() method on the model query builder. This method will include soft deleted items in the query results.


Here is an example of how to show soft deleted items in Laravel:

1
2
3
4
5
6
7
use AppModelsItem;

$softDeletedItems = Item::withTrashed()->get();

foreach ($softDeletedItems as $item) {
    echo $item->name;
}


In this example, we use the withTrashed() method on the Item model to retrieve all items, including soft deleted ones. We then loop through the items and display their names.


By using the withTrashed() method, you can easily include soft deleted items in your query results and display them as needed.