Q:

Laravel's unique:users,email validation error shows during edit

I have a form that i am using to edit a user account. I have some validation setup on the email field and i have specified that the email must be unique. The problem is when i submit the form, the validation rule that requires emails to be unique fires. That shouldn't be the case since i am editing the form and i know the email exists.
This is the code
public function servicesAdminEditUser(){
      $id = request('hidden_user_id');
      $rules = array(
          'users_telephone_number' => 'required|unique:users,users_telephone_number',
          'users_email' => 'required|email|unique:users,email',
          'users_full_names' => 'required',
          'users_gender' => 'required',
          'users_credits' => 'required',
          'users_email_verification_status' => 'required',
          'users_number_verification_status' => 'required',
          'users_moderation_status' => 'required',
          'user_role' => 'required',
          'users_profile_picture' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
          );

          $customMessages = [
    'users_telephone_number.required' => 'The telephone number is required.',
    'users_email.required' => 'We need a unique email',
    'users_full_names.required'  => 'Your full names are required',
    'users_gender.required'  => 'Gender is required',
    'users_profile_picture.required'  => 'We need your profile picture',
    'users_credits.required'  => 'User Credits Are Required',
    'users_email_verification_status.required'  => 'User email verification status is required',
    'users_number_verification_status.required'  => 'User number verification status is required',
    'users_moderation_status.required'  => 'User moderation status is required',
    'user_role.required'  => 'User role is required',
  ];

      $validator = Validator::make(Input::all(), $rules,$customMessages);
      if ($validator->fails()) {
          $messages = $validator->messages();
          return Redirect::back()->withErrors($validator);
      }
      else {
        if (Input::file('users_profile_picture')->isValid()) {
              $destinationPath = 'uploads';
              $extension = Input::file('users_profile_picture')->getClientOriginalExtension();
              $fileName = time().'_'.rand(11111,99999).'.'.$extension;
              Input::file('users_profile_picture')->move($destinationPath, $fileName);
            }
            else {
            echo 'file not valid';
            }

        $updyt = User::find($id);
        $updyt->email = request('users_email');
        //$reg->password = bcrypt(request('confirm-password'));
        $updyt->users_telephone_number = request('users_telephone_number');
        $updyt->users_email_verification_status = request('users_email_verification_status');
        $updyt->users_number_verification_status = request('users_number_verification_status');
        $updyt->users_full_names = request('users_full_names');
        $updyt->users_gender = request('users_gender');
        $updyt->users_credits = request('users_credits');
        $updyt->users_profile_picture = $fileName;
        $updyt->users_moderation_status = request('users_moderation_status');;
        $updyt->update();
        //$reg->attachRole($value);

        DB::table('role_user')->where('user_id',$id)->delete();
        $updyt->attachRole(Role::where('name',request('user_role'))->first());
        return redirect('servicesUsers');
      }
    }

If i remove the unique rule and it so happens the user editing teh accounts enters an existing email, laravel will display mysql errors that catch duplicates on the browser. How can i fix this?.

A:

Try this,
Assuming your email field name in table is email and request input mail field name is users_email and $id is the user's id present in users table.
'users_email' => 'required|email|unique:users,email,'.$id,

