When a model has a slug and is soft deleted the duplication prevention doesn't work.
Normally if the slugged property is the same you should have: slug first then slug-2 for the second.
It doesn't if slug is soft deleted.
Integrity constraint violation: 1062 Duplicate entry This is a complex use case - and a result of the fact that you require the slug to be unique on a database layer and at the same time use softdelete, which is entirely handled by the application. Think of it: For the application it is perfectly valid to have this slug, as there is no other record with this slug (the other one is deleted).
So I'd not consider this as a bug. You need to implement some custom validation in this case, or remove the UNIQUE constraint and rely on your application to handle duplicates.
Actually I thought that the my behavior was more intuitive. Since we just have to check if it exists (even trashed) or not and if so just put the -2 suffix.
This behavior is also used in Joomla. you can't create a duplicated slug even if the over one is trashed.
In my case I'll add a custom validation on the property that generates the slug. it will be easier.
I let the issue open a few days for more discussions if some users are interested in.
@Adrion I would agree with you on this. Slugs should not be reused if the original slug is still present in the db, even if that original record is soft deleted. If a record is soft deleted, it can eventually be restored and then you're in for a headache of deduplicating slugs at that point. I would accept a PR to fix the sluggable trait to look for soft deleted records to (basically just added withTrashed() to the query when it knows the soft delete trait is present).
If a record is soft deleted, it can eventually be restored and then you're in for a headache of deduplicating slugs at that point.
That's exactly what I thought, I'll check to send you a PR soon.