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);
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire