I'm building an API in Laravel 5.3 and I've to change the default response when a password is being reset.
So how would I do this without making changes to the framework. What I want is this:
In my ResetPasswords
trait located here \\Illuminate\\Foundation\\Auth\\ResetPasswords
The default response is:
/**
* Get the response for a successful password reset.
*
* @param string $response
* @return \Illuminate\Http\Response
*/
protected function sendResetResponse($response)
{
return redirect($this->redirectPath())
->with('status', trans($response));
}
/**
* Get the response for a failed password reset.
*
* @param \Illuminate\Http\Request
* @param string $response
* @return \Illuminate\Http\Response
*/
protected function sendResetFailedResponse(Request $request, $response)
{
return redirect()->back()
->withInput($request->only('email'))
->withErrors(['email' => trans($response)]);
}
What I want is this:
/**
* Get the response for a successful password reset.
*
* @param string $response
* @return \Illuminate\Http\Response
*/
protected function sendResetResponse($response)
{
return response()->json(['success' => trans($response)]);
}
/**
* Get the response for a failed password reset.
*
* @param \Illuminate\Http\Request
* @param string $response
* @return \Illuminate\Http\Response
*/
protected function sendResetFailedResponse(Request $request, $response)
{
return response()->json(['error' => trans($response)], 401);
}
So how can I accomplish that without making changes to the framework?
Copy the methods in your second codeblock to your ResetPasswordController . This will override the Trait's methods in the controller using it.
By doing so you are not making changes to the Laravel framework and your changes won't be lost on a next composer install.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.