0

I'm having trouble resetting my password. The Forget password is working good and I'm getting the email however when I click on the Reset Link button I get redirected to the password reset page and throws an error: undefined variable $errors.

Password reset is managed by Laravel doesn't it? If so then why I'm getting this

Code:

ForgetPasswordController.php

<?php

namespace App\Http\Controllers\API;

use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Password;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\MessageBag;

class ForgetPasswordController extends BaseController
{
    use SendsPasswordResetEmails;

    public function __construct()
    {
        $this->middleware('guest');
    }

    public function sendResetLinkEmail(Request $request)
    {
        $validator = Validator::make($request->only('email'), [
            'email' => 'required|email',
        ]);

        if ($validator->fails()) {
            return $this->sendError($validator->errors()->first());
        }

        // We will send the password reset link to this user.
        $response = $this->broker()->sendResetLink(
            $this->credentials($request)
        );

        if (Password::RESET_LINK_SENT == $response) {
            return $this->sendResponse('A password reset message was sent to your email address');
        }

        return $this->sendResetLinkFailedResponse($request, $response);
    }

    protected function validateEmail(Request $request)
    {
        $validator = Validator::make($request->only('email'), [
            'email' => 'required|email',
        ]);

        if ($validator->fails()) {
            return $validator->errors();
        }

        return false;
    }

    protected function sendResetLinkFailedResponse($request, $response)
    {
        $errors = $this->parseErrors(['email' => trans($response)])->first();

        return $this->sendError($errors);
    }

    protected function parseErrors($provider)
    {
        if ($provider instanceof MessageProvider) {
            return $provider->getMessageBag();
        }

        return new MessageBag((array) $provider);
    }
}

\views\auth\passwords\reset.blade.php

@extends('layouts.app')

@section('content')
<div class="container">
    <div class="row justify-content-center">
        <div class="col-md-8">
            <div class="card">
                <div class="card-header">{{ __('Reset Password') }}</div>

                <div class="card-body">
                    <form method="POST" action="{{ route('password.update') }}">
                        @csrf

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

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

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control @error('email') is-invalid @enderror" name="email" value="{{ $email ?? old('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-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="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="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required autocomplete="new-password">
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Reset Password') }}
                                </button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

enter image description here

6
  • Possible duplicate of Undefined variable: errors in Laravel Commented Nov 13, 2019 at 7:16
  • @Gulshan Not working man Commented Nov 13, 2019 at 7:25
  • provide reset.blade.php source code. As per error there is problem on that view page Commented Nov 13, 2019 at 7:29
  • @Gulshan added please check it Commented Nov 13, 2019 at 7:34
  • instead of showing an error with input try show common error with @if (isset($errors) && $errors->any()) <div class="row"> <div class="col-xs-12"> <div class="alert alert-danger alert-alt"> <strong><i class="fa fa-bug fa-fw"></i> Ошибка</strong><br> <ul> @foreach ($errors->all() as $error) <li>{{ $error }}</li> @endforeach </ul> </div> </div> </div> <br/> @endif Commented Nov 13, 2019 at 7:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.