How validate unique email out of the user that is updating it in Laravel?
In Laravel, you can use the
unique validation rule to validate that an email address is unique when a user is updating their account. The
unique rule checks that the value of the attribute being validated is not already present in the specified database table.
You can use it like this in your validation rules:
'email' => 'required|email|unique:users,email,'.$user->id
unique rule accepts three parameters: the name of the table, the name of the column, and the id of the current user. In this case, the
unique rule will check that the email address is unique among all email addresses in the
users table, except for the email address associated with the current user (specified by
It's important to note that when you are updating the user, you need to pass the user's ID to
unique rule so that it will ignore the user's current email and check the uniqueness of the new email.