In this video we are going to learn about User Change Password.
So let see how can we create change password for user or customer.
first of all lets create a new livewire component.
So switch to command prompt and for creating new livewire component run the command.

php artisan make:livewire user/UserChangePasswordComponent


Now run the application


php artisan serve


Now switch to the project and lets create the route for this new component
So just go inside the routes directory and then open web.php file.
Now here inside the user middleware route group create the new route.


Route::get('/user/change-password',UserChangePasswordComponent::class)->name('user.changepassword');


Now go to the UserChangePasswordComponent.php Class file and write following code.

<?php

namespace App\\Http\\Livewire\\User;

use App\\Models\\User;
use Illuminate\\Support\\Facades\\Auth;
use Illuminate\\Support\\Facades\\Hash;
use Livewire\\Component;

class UserChangePasswordComponent extends Component
{
public $current_password;
public $password;
public $password_confirmation;

public function updated($fields)
{
$this->validateOnly($fields,[
'current_password'=>'required',
'password' => 'required|min:8|confirmed|different:current_password'
]);
}

public function changePassword()
{
$this->validate([
'current_password'=>'required',
'password' => 'required|min:8|confirmed|different:current_password'
]);

if(Hash::check($this->current_password,Auth::user()->password))
{
$user = User::findOrFail(Auth::user()->id);
$user->password = Hash::make($this->password);
$user->save();
session()->flash('password_success','Password has been changed successfully!');
}
else
{
session()->flash('password_error','Password does not match!');
}
}

public function render()
{
return view('livewire.user.user-change-password-component')->layout('layouts.base');
}
}


Now open the user-change-password-component.blade.php view file and write following code.

<div>
<div class=\"container\" style=\"padding: 30px 0;\">
<div class=\"row\">
<div class=\"col-md-12\">
<div class=\"panel panel-default\">
<div class=\"panel-heading\">
Change Password
</div>
<div class=\"panel-body\">
@if(Session::has('password_success'))
<div class=\"alert alert-success\" role=\"alert\">{{Session::get('password_success')}}</div>
@endif
@if(Session::has('password_error'))
<div class=\"alert alert-danger\" role=\"alert\">{{Session::get('password_error')}}</div>
@endif
<form class=\"form-horizontal\" wire:submit.prevent=\"changePassword\">
<div class=\"form-group\">
<label class=\"col-md-4 control-label\">Current Password</label>
<div class=\"col-md-4\">
<input type=\"password\" placeholder=\"Current Password\" class=\"form-control input-md\" name=\"current_password\" wire:model=\"current_password\" />
@error('current_password') <p class=\"text-danger\">{{$message}}</p> @enderror
</div>
</div>
<div class=\"form-group\">
<label class=\"col-md-4 control-label\">New Password</label>
<div class=\"col-md-4\">
<input type=\"password\" placeholder=\"New Password\" class=\"form-control input-md\" name=\"password\" wire:model=\"password\" />
@error('password') <p class=\"text-danger\">{{$message}}</p> @enderror
</div>
</div>

<div class=\"form-group\">
<label class=\"col-md-4 control-label\">Confirm Password</label>
<div class=\"col-md-4\">
<input type=\"password\" placeholder=\"Confirm Password\" class=\"form-control input-md\" name=\"password_confirmation\" wire:model=\"password_confirmation\" />
@error('password_confirmation') <p class=\"text-danger\">{{$message}}</p> @enderror
</div>
</div>
<div class=\"form-group\">
<label class=\"col-md-4 control-label\"></label>
<div class=\"col-md-4\">
<button type=\"submit\" class=\"btn btn-primary\">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>


Now lets change the password.
So enter here the current password.
Now enter here new password.
And now retype the new password.
Now click on submit.
And here you can see the message password has been changed successfully!
So in this way you can create change password for user.