Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

laravel
php
communitycreator

How to retrieve soft-deleted child and parent models in Laravel

Chinweuba Elijah Azubuike

Overview

In another shot, How to soft delete a child model in Laravel, we discussed how a child model can be deleted after the parent’s model is deleted.

In this shot, we will learn how to retrieve soft-deleted data.

Usage

The main reason for not completely deleting the data is if you have future use for it and for reference purposes.

How to retrieve soft-deleted data

You can refer to this shot for instructions to install the package. Right now, we will just focus on how to retrieve the data you soft-deleted.

Use the code below in your controller where you want to retrieve the soft-deleted data.

Comments::withParentTrashed()->get();

Comments is the child model you want to retrieve.

Output

The output will be your normal array of deleted rows.

Note: This should only be done on the admin side of your application.

RELATED TAGS

laravel
php
communitycreator

CONTRIBUTOR

Chinweuba Elijah Azubuike
RELATED COURSES

View all Courses

Keep Exploring