2016-07-23 83 views
0

我想每次成功登錄時發送通知電子郵件(僅用於測試,因爲我沒有註冊郵件來測試發送電子郵件)。我修改了handleUserWasAuthenticated函數,我假設這個函數在成功登錄時會被調用。但是,我無法通過$ request變量從表單數據中獲取電子郵件和用戶名。 $ request也用在handleUserWasAuthenticated函數的其他地方默認情況下,這些情況沒有警告,只有在我添加的代碼中,$ request會收到警告「變量$請求似乎未初始化」。我怎樣才能發送電子郵件和電子郵件的用戶名?

這是AuthenticatesUser.php的handleUserWasUathenticated功能

namespace Illuminate\Foundation\Auth; 

use Illuminate\Http\Request; 
use Illuminate\Support\Facades\Auth; 
use Illuminate\Support\Facades\Lang; 

trait AuthenticatesUsers 
{ 
    use RedirectsUsers; 

    protected function handleUserWasAuthenticated(Request $request, $throttles) 
    { 
     //My modification 
     $data = [ 
      'title' => 'Welcome to Myfirstsite', 
      'content' => 'You have finished your registration successfully' 
     ]; 

     Mail::send('emails.verification', $data, function($message){ 

      $message 
       ->to($request['email'],$request['name']) 
       ->subject('Verification email from Myfirstsite'); 

     }); 

     //Original part 
     if ($throttles) { 
      $this->clearLoginAttempts($request); 
     } 

     if (method_exists($this, 'authenticated')) { 
      return $this->authenticated($request, Auth::guard($this->getGuard())->user()); 
     } 

     return redirect()->intended($this->redirectPath()); 
    } 
} 

回答

0

確保你有這樣的代碼:use Illuminate\Http\Request;

use App\Http\Requests\Request;

+0

'使用照亮\ HTTP \請求;'是在'AuthenticatesUser .php'默認。 –