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('[email protected]');
}
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('[email protected]'))->notify(new MyNotification);
And it works.