'email' => ['required', 'string', 'email', 'max:255', 'unique:users,'.$id],
Jun 17, 2020
4
Level 3
Updating user profile, keeping same email but getting 'email already taken'
Just a quick one (I hope) - I'm using Laravel 7 for this.
I'm making a user area so that people can update their name, and phone number etc.
I'm validating everything using the usual code:
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
'password' => ['required', 'string', 'min:8', 'confirmed'],
'phone' => ['required', 'string']
etc
The validation keeps telling me the email is already taken (it is, but only this specific record - it hasn't actually changed).
Is there a way for Laravel to ignore the email address being the same if it remains the same for this user but check its unique if it has been changed?
Any suggestions most appreciated. :)
Level 75
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email,'.$this->route('user')->id],
or
use Illuminate\Validation\Rule;
'email' => ['required', 'string', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
Please or to participate in this conversation.