DEV Community

Cover image for How to Use Soft Delete in Laravel
Hilmi Hidayat
Hilmi Hidayat

Posted on • Edited on

How to Use Soft Delete in Laravel

Soft delete Laravel - With eloquent, besides we can make the delete data permanent option, we can also delete temporary data, namely by soft delete. This means that with soft delete, the data that we delete is not actually permanently deleted from the database, but only adds a value to the deleted_at field in the table that we want to add the soft delete feature to.

The way soft delete works on laravel is actually almost similar to the recycle bin on windows. The data that we delete actually still exists or has not been completely deleted permanently, so it can still be restored.

We take an example from the cover of this article. On the cover above, you can see a person throwing trash in a bin. We think of the trash on the cover above as data and the trash can we think of as a recycle bin (in windows). Before the garbage or data is disposed of in a final disposal site (permanently deleted), the trash or data can still be retrieved or displayed again (restored).

How soft delete works in the database, if the data is deleted, the deleted_at field in the data will be filled with a timestamp value. Then, if the data wants to be displayed again or restored, the value in the deleted_at field (previously filled with timestamp) will be updated with NULL.

For more details on how to create or use the soft delete feature on laravel, please see and follow this article to the end. Because in this article, I will share about the steps to use the laravel soft delete feature starting from scratch, namely by installing a new laravel project, creating dummy data with a tinker, using soft delete, restoring data, to how to make a permanent delete.

read more about soft delete laravel at codelapan.com

Top comments (0)