Home > Back-end >  How can i Skip email Form unique Validation when update user data In Laravel
How can i Skip email Form unique Validation when update user data In Laravel

Time:08-13

Hello Guys And Hi I Have This Validation Inside My Request

 public function rules()
    {
        return [
        'email' => 'required|email|unique:admins,email,' ,
        'name' => 'required|unique:admins,name',
        'code' => 'required|min:2|unique:admins,code',
        'password' => 'required|min:8',

        ];
    }

I want to ignore an email when updating data during the unique check. For example, consider an "update profile" screen that includes the user's name, e-mail address, I want to verify that the e-mail address is unique. However, if the user only changes the name field and not the e-mail field, I do not want a validation error to be thrown because the user is already the owner of the e-mail address. I only want to throw a validation error if the user provides an e-mail address that is already used by a different user.

CodePudding user response:

I'm Fixing It I'm Passing The Id To The Request Like This

<input name='id' value="$item -> id" hidden >

and i write in Validation

  'email' => 'required|email|unique:admins,email,' . $this -> id ,
  • Related