Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How validate unique email out of the user that is updating it in Laravel?

I am using Laravel 5.2 and want to update user's account using validator.

I want to keep email field unique, but, if the user type his current email it will break. How can I update if the email is unique, except the user's own current email?

like image 824
Luiz Avatar asked Dec 02 '16 23:12

Luiz


People also ask

Is unique validation in laravel?

Laravel includes a wide variety of convenient validation rules that you may apply to data, even providing the ability to validate if values are unique in a given database table.

How can I check if an email address is valid in PHP?

The easiest and safest way to check whether an email address is well-formed is to use PHP's filter_var() function.


1 Answers

You can tell that to validators:

'email' => 'unique:users,email_address,'.$user->id 

Check the docs, in section 'Forcing A Unique Rule To Ignore A Given ID'.

like image 157
Antonio Carlos Ribeiro Avatar answered Oct 10 '22 01:10

Antonio Carlos Ribeiro