Search code examples
laravellaravel-livewire

Password confirmation does not match in livewire


I am trying to implement a registration form using livewire but I get a validation error that password does not match, where is the problem?

my livewire

public $name;
public $email;
public $password;
public $businessName;
public $passwordConfirmation;
public function createUser(){

        $this->validate([
            'name'=>'required|max:100',
             'email'=>'required|email|max:255|unique:users',
            'password'=>'required|min:8|confirmed',
            'passwordConfirmation' => 'required ',
        ]);
        
        $data=[

            'name'=>$this->name,
            'email'=>$this->email,
            'password'=>Hash::make($this->password)
        ];
        return User::create($data);
    }

and my view

<div class="row mb-3">
   <label for="password"  class="col-md-4 col-form-label text-md-end">{{ __('Password') }}</label>
   <div class="col-md-6">
      <input id="password" wire:model='password'  type="password" class="form-control @error('password') is-invalid @enderror" name="password" required autocomplete="new-password">
      @error('password')
      <span class="invalid-feedback" role="alert">
      <strong>{{ $message }}</strong>
      </span>
      @enderror
   </div>
</div>
<div class="row mb-3">
   <label for="password-confirm" class="col-md-4 col-form-label text-md-end">{{ __('Confirm Password') }}</label>
   <div class="col-md-6">
      <input id="password-confirm" wire:model="passwordConfirmation"  type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
   </div>
</div>

Solution

  • password_confirmation you need to add in the validation

    i.e, example

    $this->validate($request, [
        'password' => 'required',
        'password_confirmation' => 'required_with:password|same:password|min:6'
    ]);
    

    But you used different keyword for the field name "passwordConfirmation". Ref