Home / Snippets / How to Restore Multiple Soft Deleted Model in Laravel
How to Restore Multiple Soft Deleted Model in Laravel cover

How to Restore Multiple Soft Deleted Model in Laravel

260

2 years ago

0 comments

To restore multiple soft deleted models in Laravel, you can make use of a wildcard method to query for multiple values such as using "where()" clause and then call "restore()" to restore multiple of the soft-deleted rows.

Individual Restore
The typical individual restore code will be as follows.
<?php

Post::withTrashed()->find(1)->restore();

Multiple Restore
Instead of retrieving 1 row like the code above, by making use of "where()" clause, you can restore multiple rows at once.
<?php

Post::withTrashed()->where('id', '>', 5)->restore();

Assuming you have 10 posts that have been soft deleted, running the code above will make the post from id 6 to 10 restored.
notion avatar

Ahmad Aziz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

If you like our tutorial, support us by being our Patreon or buy us some coffee ☕️

Post Tutorials

Learn trending tutorials for ReactJs, React Native, VueJS, NextJs, Laravel, Tailwind CSS, and Flutter development.
View Tutorials

Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your web projects
View Components

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this