TextInput unique w/o softDelete
Hi all !
Is there an elegant way to test that a TextInput is unique in the database by ignoring softDeletes? Regards
10 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
If you ignore the soft deletes then you will not be able to restore the soft deleted model.
It's just about the unique rule.
What do you mean by "ignoring softDeletes"? There may be one entry with the same value if it's soft deleted? You probably need a custom rule for that one
Shouldn’t this coincide with a unique on the table too though. Otherwise there’s no safety.
Well if the requirement is "unique but only non-softdeleted" that's probably not possible on DB level, is it?
that's my point. Unique checks the database so, ignoring the soft delete would result in 2 or more database entries with non unique fields.
Really if your doing what you are suggesting you should move the the data out of the table, storing it in a trashed table for instance, then on restoring should you wish you can check for conflicts.
You can do as you suggest but to me that’s proposing lots of inconsistencies
This looks cool not played with it yet wonder if there’s a filament package to easily integrate? https://freek.dev/2416-a-package-to-automatically-copy-deleted-records-to-a-separate-table
A package to automatically copy deleted records to a separate table...
We've released a new package called spatie/laravel-deleted-models. When deleting a model, this package will copy over its attributes to a table called deleted_models.
You can view this package as a "Recycle bin for models".
In this post, I'd like to tell you all about it.
No need for filament, I believe that’s handled on the models if memory serves me right
Good question...I don't know yet 😁
You're right
You're right too
this seems to be a reasonable solution, I'll take a closer look
just to clarify, I actually use the softDelete but without a restore solution. the goal is just to keep a history of what has existed.
thanks to all guys !