2017-08-26 139 views
1

我試圖通過AJAX發送密碼重置鏈接。我已經重寫我的內sendResetLinkEmail方法如下:覆蓋sendResetLinkEmail什麼都不會返回

public function sendResetLinkEmail() 
{ 
    $this->validate(request(), ['email' => 'required|email|exists:users']); 

    $response = $this->broker()->sendResetLink(
     request()->only('email') 
    ); 

    echo 'test'; 
} 

驗證完美的作品和我得到一個responseJSON回來,如果有錯誤,例如無效的電子郵件,不存在的電子郵件。我的問題是,當沒有驗證錯誤時,我沒有收到任何類型的響應。不是test,完全不是。

當我刪除下面我得到test回的響應:

$response = $this->broker()->sendResetLink(
    request()->only('email') 
); 

它沒有意義。

回答

0

你應該嘗試這可能是它的幫助!

use Illuminate\Http\Request; 

public function sendResetLinkEmail(Request $request) 
    { 
     $this->validateEmail($request); 

     // We will send the password reset link to this user. Once we have attempted 
     // to send the link, we will examine the response then see the message we 
     // need to show to the user. Finally, we'll send out a proper response. 
     $response = $this->broker()->sendResetLink(
      $request->only('email') 
     ); 

     return $response == Password::RESET_LINK_SENT 
        ? $this->sendResetLinkResponse($response) 
        : $this->sendResetLinkFailedResponse($request, $response); 
    } 
0

問題在於它無法連接到SMTP服務器,因此掛起。

這裏是工作代碼:

public function sendResetLinkEmail() 
{ 
    $this->validateEmail(request()); 

    $response = $this->broker()->sendResetLink(
     request()->only('email') 
    ); 

    if ($response == Password::RESET_LINK_SENT) { 
     return response()->json([ 
      'alert' => true, 
      'alert_message' => 'Password reset link emailed!', 
     ]); 
    } 
    else { 
     return response()->json(['email' => trans($response)], 422); 
    } 
} 

我用data.hasOwnProperty('alert')在我的jQuery代碼,以確定是否應當在success AJAX響應顯示一個警告。