Laravel邮件通知

With Laravel 5.3, I can define recipient in a Notification:

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

public function toMail($notifiable)
{
    return (new MailMessage)->line('hello')->to('me@example.com');
}

Since Laravel 5.4 (relevant commit), I can't use to. How can I update my code? I need to send a notification to an email which is not bound to a user nor an object. How to "hack" these missing functionality?

Create a minimal class with an email property:

class MyNotifiable
{
    use \Illuminate\Notifications\Notifiable;

    public $email;

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

Then call notify on your minimal class:

(new MyNotifiable('me@example.org'))->notify(new MyNotification);

And it works.

Have you looked at the master branch of the same file?

It has been reverted:

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

Also the documentation has 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);
}

Hope it helps you.