I'm trying to set up a client registration check and profile edit.
- I'm using soft delete
- E-mail has to be unique (not counting the delted ones of course)
- If profile is edited (id is present) it has to ignore that fields email
So far I have
'email' => [
'required',
'email',
'unique:clients,email,NULL,deleted_at,deleted_at,NULL',
],
Now this works correctly and detects the unique emails that are not deleted, but it gives me errors when I need to edit the profile off the client. I tried adding additional unique settings, but they seem to be getting ignored:
'email' => [
'required',
'email',
'unique:clients,email,NULL,deleted_at,deleted_at,NULL',
Rule::unique('clients')->ignore('id', (int)$request->input('id')) // <- from Laravel docs, but is not working
],
I found solutions with only one of these requirements, but I can't seem to combine them.
Edit: The fix was
'email'=>['required','email',Rule::unique('clients','email')->ignore($request->input('id'))->whereNull('deleted_at')],