2016-08-11 83 views
1

我想手動向控制器內的特定用戶(不是當前登錄的用戶)發送密碼重置請求。我在Laravel代碼中進行了一些挖掘,似乎我應該在ResetsPasswords中調用postEmail(Request $request),但我似乎無法弄清楚如何訪問正確的PasswordController實例來調用它。如何在Laravel 5.2中手動發送密碼重置請求?

+0

您是否嘗試過,包括做'使用ResetsPasswords性狀;'你的控制器中,然後調用從性狀相關的方法是什麼? – Jonathon

+0

@Jonathon是的。我使用過'使用ResetsPasswords'和'$ this-> postEmail($ request);'。沒有輸出;既沒有錯誤也沒有成功,但我從來沒有收到電子郵 –

+0

更新您的auth.php配置文件驅動程序 – ClearBoth

回答

5

爲什麼不乾脆像這樣爲你的控制器:

<?php 

namespace Illuminate\Foundation\Auth; 

use Illuminate\Http\Request; 
use Illuminate\Mail\Message; 
use Illuminate\Support\Facades\Password; 

class YourController extends Controller 
{ 
    public function sendEmail() 
    { 
     $credentials = ['email' => $email_address]; 
     $response = Password::sendResetLink($credentials, function (Message $message) { 
      $message->subject($this->getEmailSubject()); 
     }); 

     switch ($response) { 
      case Password::RESET_LINK_SENT: 
       return redirect()->back()->with('status', trans($response)); 
      case Password::INVALID_USER: 
       return redirect()->back()->withErrors(['email' => trans($response)]); 
     } 
    } 
} 

你真的不解釋,你要如何發送此背景下,所以相應的調整。

+0

謝謝 - 這讓我走上了正軌!我剛剛編輯了這篇文章,以明確sendResetLink的第一個參數應該是'['email'=> $ email_address]' –

+0

'的數組,真棒,很高興聽到! –

+0

你救了我的一天,夥計! – oskarko

0

5.5完全控制:

$user = User::where('email', request()->input('email'))->first(); 
    $token = Password::getRepository()->create($user); 

    Mail::send(['text' => 'emails.password'], ['token' => $token], function (Message $message) use ($user) { 
     $message->subject(config('app.name') . ' Password Reset Link'); 
     $message->to($user->email); 
    });