简体   繁体   English

如何在不更改唯一字段值的情况下进行更新?

[英]How to update without changing the value of unique fields?

I update user data.我更新用户数据。 Form of update is fill current user data.更新的形式是填写当前用户数据。 And if I don't change email validation show me error that this email already been taken.如果我不更改 email 验证,则会显示此 email 已被占用的错误。 I use Rule::unique that resolve this problem but this not working?我使用Rule::unique来解决这个问题,但这不起作用?

Fix previous answer修复之前的答案

class CustomerRequest extends FormRequest
{
    public function rules()
    {
     return [
       'first_name'   => 'min:3|max:20|regex:/^[a-zA-z-0-9]+$/u',
       'last_name'    => 'min:3|max:30|regex:/^[a-zA-z-0-9]+$/u',
       ['email', Rule::unique('customers')->ignore($this->customer->id)]      
     ];
}

Also in your controller must receive另外在你的controller必须收到

public function update(CustomerRequest $request, Customer $customer)
    {
        //Code
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM