Skip to content
Advertisement

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry ‘0430142821’ for key ‘users_melli_unique’

I know this question asked before but i want to know how can i stop to showing this error and instead of this i want to show custom error message to user in blade.

This is user migration :

JavaScript

UPDATE: This is my insert function :

JavaScript

This error happens when i have a melli in my database like 1234567890 and i try to write 1234567890 again, because the melli field is unique.

Advertisement

Answer

You need unique validation rule and ignore that id in the update.

You can do like this:

JavaScript

Or

JavaScript

I think that’s what you need.

Also, some helpful answer.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement