2
我在Laravel 5.3中構建了一個API,並且在密碼重置時我必須更改默認響應。Laravel更改密碼重置響應
那麼,如何做到這一點,而無需更改框架。我想是這樣的:
在我設在這裏ResetPasswords
特質\Illuminate\Foundation\Auth\ResetPasswords
默認響應是:
/**
* 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)]);
}
我想是這樣的:
/**
* 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);
}
所以,我怎麼能在不改變框架的情況下做到這一點?