Search code examples
laravelsoft-delete

how to constraint data to keep right data in soft delete laravel


I intend to use soft delete for my laravel project and i wonder how to assure data alway right ?

My thought is like this: to create soft delete i have to create delete_at column to use soft delete. But what will happen if i insert a record exactly same the 'deleted' record (except value of delete_at column ) ?

If delete_at isn't in primary key then i cannot add new record right ? But what if i put delete_at into primary key ? I think it's a bad idea.

How can i solve this issue ?


Solution

  • In case of soft deletes, one uses almost always auto-incremented integer primary keys to avoid constraint violations caused by reinsertion.