2017-02-07 96 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