通过验证更新laravel中的问题

时间:2016-07-01 06:32:37

标签: laravel

如何验证我是否通过电子邮件提升整个个人资料,电子邮件验证工作正常。但是当我更新配置文件而不更改电子邮件时,验证不会让代码运行。请告诉我如何修复电子邮件应该是唯一的,但是当我不更改电子邮件时它也会更新个人资料

        $validation_rules['user_id'] = 'required';
        $validation_rules['name'] = 'required';
        $validation_rules['email'] = 'email|required|unique:users,email';
        $validation_rules['phone'] = 'required';

1 个答案:

答案 0 :(得分:0)

$validation_rules['user_id'] = 'required';
$validation_rules['name'] = 'required';
$validation_rules['phone'] = 'required';

if (Request::isMethod('put')) {
    //which is update
    $validation_rules['email'] = 'email|required';
}else{
    // if it is not 'put', it is 'post' which is an insert
    $validation_rules['email'] = 'email|required|unique:users,email';
}

如果有效,请告诉我