I get this error in my custom application:
InvalidArgumentException in UrlGenerator.php line 304:
Route [password.reset] not defined.
I know that laravel provides reset password functionality out of the box, but I want to write my own class and routes.
Here are my routes in web.php
Route::get('password/email', 'Auth\PasswordController@getResetEmail');
Route::post('password/email', 'Auth\PasswordController@postResetEmail');
Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');
And this is my PasswordController:
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Contracts\Auth\PasswordBroker;
use Illuminate\Foundation\Auth\ResetsPasswords;
class PasswordController extends Controller {
use ResetsPasswords;
public function __construct(Guard $auth, PasswordBroker $passwords)
{
$this->auth = $auth;
$this->passwords = $passwords;
$this->middleware('guest');
}
}
This is my sign of ResetPasswords.php:
namespace Illuminate\Foundation\Auth;
use Illuminate\Http\Request;
use Illuminate\Mail\Message;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Password;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
trait ResetsPasswords
{
use RedirectsUsers;
public function getResetEmail()
{
return view('public.auth.password');
}
public function postResetEmail(Request $request)
{
$this->validate($request, ['email' => 'required|email']);
$response = Password::sendResetLink($request->only('email'), function (Message $message) {
$message->subject($this->getEmailSubject());
});
switch ($response) {
case Password::RESET_LINK_SENT:
return redirect()->back()->with('status', trans($response));
case Password::INVALID_USER:
return redirect()->back()->withErrors(['email' => trans($response)]);
}
}
protected function getEmailSubject()
{
return property_exists($this, 'subject') ? $this->subject : 'Your Password Reset Link';
}
public function getReset($token = null)
{
if (is_null($token)) {
throw new NotFoundHttpException;
}
return view('public.auth.reset')->with('token', $token);
}
public function postReset(Request $request)
{
$this->validate($request, [
'token' => 'required',
'email' => 'required|email',
'password' => 'required|confirmed|min:6',
]);
$credentials = $request->only(
'email', 'password', 'password_confirmation', 'token'
);
$response = Password::reset($credentials, function ($user, $password) {
$this->resetPassword($user, $password);
});
switch ($response) {
case Password::PASSWORD_RESET:
return redirect($this->redirectPath())->with('status', trans($response));
default:
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
}
}
protected function resetPassword($user, $password)
{
$user->password = bcrypt($password);
$user->save();
Auth::login($user);
}
}
The problem is that when I click the password reset form button, it leads to this error. I don’t know what the problem is, but it seems phpstorm cannot recognize the Password :: sendResetLink method in the PasswordBroker class and selects the method with yellow color and shows this bubble message:
Method sendResetLink not found in Illuminate\Support\Facades\Password
Refreced method is not found in subject class
I don’t know what is the connection between this method and routes?
Any help would be appreciated ...