How to Soft Delete on Laravel 5

How to Soft Delete on Laravel 5

SHARE

These are the steps on how to Soft Deletes records in your Laravel app. You can refer also the official docs at Soft Deleting.

In case you didn’t understand what soft deleting is, it is a process of deleting a record that is being displayed in your application, without deleting the actual record in the database. In other words, you just prevent your app from displaying all the soft deleted records but keeping it in your actual database.

Some find this method useful, especially if you don’t want user to actually delete a record, or to keep tracking of what records are being deleted, and who deleted those records.

Laravel 5 provides a very simple way on how to soft delete a record. Follow the steps along.

Some Notes before proceeding:

  • In case you don’t use migration, just add a datetime() field named ‘deleted_at‘. And it should be nullable.
  • If you use data migration just add  $table->softDeletes(); just below the $table->timestamps();
Prev1 / 3

SHARE
Programmer, Database Designer and Administrator for Web Application. Who loves to read and write interesting topics.

11 COMMENTS

  1. Hey, what if there’s a unique column in the table? What happens when we add data that has the same value as the soft deleted one?

  2. it would not add data, the purpose of softdelete is to tag records you want not to display but dont want to delete it.

    So you have to decide if you have to permanently delete the softdeleted one and add new record or restore the softdeleted one.

  3. Hi, just required you to know I he added your site to my Google bookmarks due to your layout. But seriously, I believe your internet site has 1 in the freshest theme I??ve came across. It extremely helps make reading your blog significantly easier.

  4. I simply want to mention I am just newbie to blogging and site-building and certainly enjoyed this website. Very likely I’m likely to bookmark your site . You definitely come with really good well written articles. Many thanks for revealing your webpage.

  5. I simply want to say I am just all new to blogging and site-building and seriously enjoyed this web blog. Very likely I’m likely to bookmark your website . You actually have remarkable articles and reviews. Kudos for sharing your webpage.

  6. I simply want to tell you that I’m all new to blogs and absolutely loved this web site. More than likely I’m likely to bookmark your blog post . You actually have great articles and reviews. Regards for revealing your website page.

  7. When I originally commented I clicked the -Notify me when new comments are added- checkbox and today each time a comment is added I am four emails with the same comment. Will there be however you can get rid of me from that service? Thanks!

  8. Thank you a lot for providing individuals with an extremely memorable possiblity to read articles and blog posts from this blog. It is often very pleasing and also stuffed with fun for me personally and my office acquaintances to search your website at the least thrice a week to read the latest secrets you have got. Of course, I’m always happy considering the dazzling tactics you give. Some 3 points in this posting are really the most efficient we have ever had.

LEAVE A REPLY