Append the id
of the instance currently being updated to the validator.
Pass the id
of your instance to ignore the unique validator.
In the validator, use a parameter to detect if you are updating or creating the resource.
If updating, force the unique rule to ignore a given id:
//rules
'email' => 'unique:users,email_address,' . $userId,
If creating, proceed as usual:
//rules
'email' => 'unique:users,email_address',
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…