2017-02-07 9 views
0

、私は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) - > to(([email protected])); –

答えて

1

電子メールのプロパティで、最小限のクラスを作成します。

(new MyNotifiable('[email protected]'))->notify(new MyNotification); 
をそして、それは動作します:

class MyNotifiable 
{ 
    use \Illuminate\Notifications\Notifiable; 

    public $email; 

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

その後、あなたの最小限のクラスにnotifyを呼び出します。

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

関連する問題