J
J
juan_chikatilo2022-04-03 20:40:57
Laravel
juan_chikatilo, 2022-04-03 20:40:57

How to make Validator unique on soft delete?

Hello!
Added soft deletion of users. It works, but unique doesn't care about the deleted_at column.
'email' => 'required|email|unique:users,email',
Is it possible to somehow add a condition to it to skip email when the deleted_at field is not null.
Or will you have to delete this rule and make a query to the database yourself for the search?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TheAndrey7, 2022-04-03
@TheAndrey7

The rule works as it should. Imagine what will happen if you restore a deleted user, and E-mail is busy.
You need soft-deleted users after a certain period of time to delete forever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question