Laravel 4 Form Validation should be unique on update form, but not if current

前端 未结 2 771
余生分开走
余生分开走 2021-01-28 05:16

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

2条回答
  •  长发绾君心
    2021-01-28 05:41

    You can accomplish this with the sometimes function of the validator

    Something like:

    $validator->sometimes('email', 'unique:users,email', function ($input) {
        return $input->email == Input::get('email');
    });
    

    See http://laravel.com/docs/4.2/validation#conditionally-adding-rules for more info

提交回复
热议问题