How to change password?

Posted 2 months ago by irankhosravi

I want to edit form form update only address, email and password. How to change password?

Old Password is important.

edit.blade.php

<form method="POST" action="{{ route('update') }}">
    @csrf
    {{ method_field('PATCH') }}
    <div class="form-group row">
        <label for="email" class="col-md-1 col-form-label text-md-right">{{ __('Email') }}</label>

        <div class="col-md-5">
            <input id="email" type="text" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ old('email') ? : user()->email }}" required autocomplete="email" autofocus>

            @error('email')
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
        </div>
    </div>

    <div class="form-group row">
        <label for="password" class="col-md-1 col-form-label text-md-right">{{ __('Password') }}</label>

        <div class="col-md-5">
            <input id="password" type="text" class="form-control @error('password') is-invalid @enderror" name="password" value="{{ old('password') }}" required autocomplete="password" autofocus>

            @error('password')
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
        </div>
    </div>

    <div class="form-group row">
        <label for="address" class="col-md-1 col-form-label text-md-right">{{ __('Address') }}</label>

        <div class="col-md-5">
            <textarea id="address" type="text" class="form-control @error('address') is-invalid @enderror" name="address" required autocomplete="address" autofocus>{{ old('address') ? : user()->address }}</textarea>

            @error('address')
            <span class="invalid-feedback" role="alert">
                    <strong>{{ $message }}</strong>
                </span>
            @enderror
        </div>
    </div>

    <div class="form-group row mb-0">
        <div class="col-md-1">
            <button type="submit" class="btn btn-block btn-primary">
                {{ __('Register') }}
            </button>
        </div>
    </div>
</form>

web.php

Route::post('update', 'Auth\[email protected]')->name('update');

RegisterController.php

 public function sqlupdate(Request $request)
{
    Auth::user()->update([
        'address' => $request['address'],
        'email' => $request['email'],
    ]);

    $hashedPassword = auth()->user()->password;
    if (Hash::check($request->oldpassword, $hashedPassword)){
        $user = User::findOrFail(Auth::id());
        $user->password = Hash::make($request->password);
    }
    return redirect()->back();
}

Please sign in or create an account to participate in this conversation.