#How would you set unique constraints, but ignore if row is soft deleted?

15 messages · Page 1 of 1 (latest)

untold dirge
#
$table->unique(['key', 'deleted_at']);
#

That is what you're looking for.

#

I believe that should work fine.

little night
untold dirge
#

That is fine, because they don't care about deleted_at items. However, when they aren't deleted - it is null, and ignored.

#

So only the key will be used for unique.

#

Then when it is deleted, the date will be used as well making it no longer match the unique qualifier.

#

Which is what they are looking for.

little night
#

My bad… shouldn’t be checking my phone halfway though the night and trying to make sense of things…

sour wing
#

I gave it one more shot

#

and now it works

#

probably I was screwing up on something at some point

#

ty btw @little night

true lake
#

@sour wing You should reuse the historical record instead of creating a new record.