Hey Everybody!
I'm using Laravel with SoftDeletes and need a unique constraint on the combination of product_id and type_id. When I soft delete a record and try to insert the same combination again, the database throws a unique constraint error, even though the original record is soft deleted. While soft deletes aren't immediately required, I may need to recover deleted data in the future. How can I structure this to prevent the unique constraint issue while still allowing future data recovery if necessary?
Any suggestions on the best approach please.
Back
•
In response to @Asmit
Soft delete works on laravel level and unique constraint works on database level. Technically this is the default behaviour. I am not sure if this is the correct approach but maybe add deleted_at as well to the constraint.. but this might break the what you already have. Maybe try to manage this unique constraint on model level or via validation rules on form request