2017-02-07 122 views
0

隨着Laravel 5.3,我可以在Notification定義收件人:Laravel郵件通知

// In a class extending Illuminate\Notifications\Notification : 

public function toMail($notifiable) 
{ 
    return (new MailMessage)->line('hello')->to('[email protected]'); 
} 

由於Laravel 5.4(relevant commit),我不能使用to。我如何更新我的代碼?我需要將通知發送給未綁定到用戶或對象的電子郵件。如何「破解」這些缺失的功能?

+0

您發送的對象必須是Mailable 將新的Mailable($ this-> invoice) - >轉換爲('[email protected]'); –

回答

1

與電子郵件屬性創建一個最小的類:

class MyNotifiable 
{ 
    use \Illuminate\Notifications\Notifiable; 

    public $email; 

    public function __construct($email) 
    { 
     $this->email = $email; 
    } 
} 

然後調用notify您的最小類:

(new MyNotifiable('[email protected]'))->notify(new MyNotification); 

和它的作品。

0

你看過同一個文件的主分支嗎?

已恢復:

https://github.com/laravel/framework/blob/master/src/Illuminate/Notifications/Channels/MailChannel.php

另外,文檔有to()

use App\Mail\InvoicePaid as Mailable; 

/** 
* Get the mail representation of the notification. 
* 
* @param mixed $notifiable 
* @return Mailable 
*/ 
public function toMail($notifiable) 
{ 
    return new Mailable($this->invoice)->to($this->user->email); 
} 

希望它可以幫助你。

+0

謝謝。它是關於'MailMessage',而不是'Mailable'。 '(to)'仍然不存在於https://github.com/laravel/framework/blob/master/src/Illuminate/Notifications/Messages/MailMessage.php –

+0

我希望你正在尋找'replyTo()'它在這裏:https://github.com/laravel/framework/blob/master/src/Illuminate/Notifications/Messages/MailMessage.php#L118 – PaladiN