I am trying to reset my password but i am unable to solve my problem and i am stuck in this issue and hours has been passed but i cant figure out where is the issue:

My Controller:

  class ResetPasswordController extends Controller
   {
protected $user;



public function __construct(User $user)
{
    // set the model
    $this->user = $user;

}
public function showResetForm(Request $request, $token = null)
{
    return view('auth.passwords.reset')->with(
        ['token' => $token, 'email' => $request->email]
    );
}

public function reset(Request $request)
{
    $validator = UserValidations::changePassword($request->all());

    if($validator->fails()) {
        return response(['status' => false,'message' => __('messages.validation_errors'), 'errors' => $validator->errors()->all()], 200);
    }

    try {
        $password = $this->user->where('id', Auth::user()->id)->value('password');

        if(Hash::check($request->input('current_password'),$password)) {

            $this->user->where('id', Auth::user()->id)->update(['password' => bcrypt($request->input('new_password'))]);

            $token = $request->header('Authorization');

            JWT::invalidate($token);

            Auth::logout();

            return response(['status' => true, 'message' => 'Password changed successfully'], 200);

        } else {
            return response(['status' => false, 'message' => 'The Current Password is invalid.'], 200);
        }
    } catch (\Exception $ex) {
        return response(['status' => false, 'message' => $ex->getMessage()], 500);
    }
}

}

my view:

                    <form class="form-horizontal" method="POST" action="{{ route('password.request') }}">
                    {{ csrf_field() }}

                    <input type="hidden" name="token" value="{{ $token }}">

                    <div class="form-group{{ $errors->has('current_password') ? ' has-error' : '' }}">
                        <label for="password" class="col-md-4 control-label">Current Password</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control" name="current_password" required>

                            @if ($errors->has('current_password'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('current_password') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('new_password') ? ' has-error' : '' }}">
                        <label for="password" class="col-md-4 control-label">Password</label>

                        <div class="col-md-6">
                            <input id="password" type="password" class="form-control" name="new_password" required>

                            @if ($errors->has('new_password'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('new_password') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group{{ $errors->has('new_password_confirmation') ? ' has-error' : '' }}">
                        <label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
                        <div class="col-md-6">
                            <input id="password-confirm" type="password" class="form-control" name="new_password_confirmation" required>

                            @if ($errors->has('new_password_confirmation'))
                                <span class="help-block">
                                    <strong>{{ $errors->first('new_password_confirmation') }}</strong>
                                </span>
                            @endif
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-md-6 col-md-offset-4">
                            <button type="submit" class="btn btn-primary">
                                Reset Password
                            </button>
                        </div>
                    </div>
                </form>

But it saying trying to get property on non-object please help me on this your help will be highly appreciated i have also attached the screen shot of my 1st screen where there is 3 input fields and 2nd screen shot of error Your help needs please

enter image description here

1 Answers

0
Yegor Keller On

Did you bind user parameter in your Route Facade/ServiceProvider ?

If you don't do it just add somewhere in you route password.request user id to implicit model binding. Your error most probably because you have an empty user object output of your __construct().