I am trying to validate an update user profile form, whereby the validation should check that the email doesn't exist already, but disregard if the users existing email remains.
However, this continues to return validation error message 'This email has already been taken'.
I'm really unsure where I'm going wrong. Otherwise, the update form works and updates perfectly.
HTML
{{ Form::text('email', Input::old('email', $user->email), array('id' => 'email', 'placeholder' => 'email', 'class' => 'form-control')) }}
Route
Route::post('users/edit/{user}', array('before' => 'admin', 'uses' => 'UserController@update'));
User Model
'email' => 'unique:users,email,{{{ $id }}}'
Your rule is written correctly in order to ignore a specific id, however, you'll need to update the value of
{{{ $id }}}
in your unique rule before attempting the validation.I'm not necessarily a big fan of this method, but assuming your rules are a static attribute on the
User
object, you can create a static method that will hydrate and return the rules with the correct values.You can accomplish this with the sometimes function of the validator
Something like:
See http://laravel.com/docs/4.2/validation#conditionally-adding-rules for more info