2016-09-15 130 views
0

我試圖在laravel上排列密碼重置郵件。Laravel郵件隊列密碼重置

我曾嘗試克隆PasswordBroker如下:如果我改變mailer->queuemailer->send它工作正常

exception 'ErrorException' with message 'Serialization of closure failed: Serialization of closure failed: Serialization of 'Closure' is not allowed' 

<?php 
namespace App; 

use Closure; 
use Illuminate\Auth\Passwords\PasswordBroker as IlluminatePasswordBroker; 
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract; 

class PasswordBroker extends IlluminatePasswordBroker 
{ 

    public function emailResetLink(CanResetPasswordContract $user, $token, Closure $callback = null) 
    { 
    // We will use the reminder view that was given to the broker to display the 
    // password reminder e-mail. We'll pass a "token" variable into the views 
    // so that it may be displayed for an user to click for password reset. 
     $view = $this->emailView; 

     return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user, $token, $callback) { 
      $m->to($user->getEmailForPasswordReset()); 

      if (! is_null($callback)) { 
       call_user_func($callback, $m, $user, $token); 
      } 
     }); 
    } 

} 

然後我得到這個錯誤。我無法弄清楚發生了什麼事。

回答

0

當您將某些東西放入隊列中時,Laravel將其序列化爲純文本,並將其存儲到數據庫中 - 無法使用對象執行此操作。

取而代之:創建一個Job,捕獲發送電子郵件所需的所有信息(用戶,標記等),然後在調用作業時,照常調用mail函數。

0

您需要將用戶的電子郵件ID聲明一個變量,然後把它傳遞給郵件功能

public function emailResetLink(CanResetPasswordContract $user, $token, Closure $callback = null) 
    { 
     $view = $this->emailView; 
     $to = $user->getEmailForPasswordReset(); 


     return $this->mailer->queue($view, compact('token', 'user'), function ($m) use ($user,$to, $token, $callback) { 
      $m->to($to); 

      if (! is_null($callback)) { 
       call_user_func($callback, $m, $user, $token); 
      } 
     }); 
    } 
+0

這didn't工作...我已經嘗試過... – dante