Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

idcreatv's avatar

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. :)

0 likes
4 replies
ajithlal's avatar
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,'.$id],
idcreatv's avatar

Thanks for the headsup - I did try this:

'email' => ['required', 'string', 'email', 'max:255', 'unique:users,' . $id],

But I got this error:

SQLSTATE[42S22]: Column not found: 1054 Unknown column '4' in 'where clause' (SQL: select count(*) as aggregate from `users` where `4` = [email protected]

P.S. 4 is the ID of the user being updated.

Please or to participate in this conversation.