I am using Laravel 5.3 My ForgotPasswordController looks like that:
<?php namespace AppHttpControllersAuth; use AppHttpControllersBaseBaseController; use IlluminateFoundationAuthSendsPasswordResetEmails; class ForgotPasswordController extends BaseController { use SendsPasswordResetEmails; public function __construct() { $this->middleware('guest'); } public function showLinkRequestForm() { $title = $this->title; $appName = $this->appName; $action = $this->action; return view('password.forgotPassword')->with(compact('title', 'appName', 'action')); } }
ResetPasswordController code :
<?php namespace AppHttpControllersAuth; use AppHttpControllersBaseBaseController; use IlluminateFoundationAuthResetsPasswords; class ResetPasswordController extends BaseController { use ResetsPasswords; public function __construct() { $this->middleware('guest'); } public function showResetForm(Request $request, $token = null) { return view('passwords.resetPassword')->with( ['token' => $token, 'email' => $request->email] ); } public function reset(Request $request) { $this->validate($request, [ 'token' => 'required', 'password' => 'required|confirmed|min:6', ]); // Here we will attempt to reset the user's password. If it is successful we // will update the password on an actual user model and persist it to the // database. Otherwise we will parse the error and return the response. $response = $this->broker()->reset( $this->credentials($request), function ($user, $password) { $this->resetPassword($user, $password); } ); // If the password was successfully reset, we will redirect the user back to // the application's home authenticated view. If there is an error we can // redirect them back to where they came from with their error message. return $response == Password::PASSWORD_RESET ? $this->sendResetResponse($response) : $this->sendResetFailedResponse($request, $response); } }
My Admin Route :
Route::group(['namespace' => 'Auth'], function() { Route::get('/forgotpassword/reset', 'ForgotPasswordController@showLinkRequestForm'); Route::post('/forgotpassword/email', 'ForgotPasswordController@sendResetLinkEmail'); Route::get('/password/reset/{token}', 'ResetPasswordController@showResetForm'); Route::post('/password/reset', 'ResetPasswordController@reset'); });
BaseController Code :
<?php namespace AppHttpControllersBase; use AppHttpControllersController; class BaseController extends Controller { protected $appName = 'Stackoverflow'; protected $title = 'Welcome to Stackoverflow'; protected $action; }
I can send the link to my email, but once I click the link/button. It throws an error like above. Any idea ?
Advertisement
Answer
You are not using the required namespace, try to use the following in your controller:
use IlluminateHttpRequest;
You are getting the error due to the fact that your script tries to load the Request
class from the current namespace :AppHttpControllersAuth