4
votes

When using Notifications in Laravel (5.5), you can access the Notifiable (the recipient) from within the toMail() method.

Is there an equivalent way to access the recipient when you are sending a Mailable?

Is there a better solution than just repeating the User instance in the constructor like this?

Mail::to($user)->send(new EventAlert($user));
1

1 Answers

2
votes

No, there is no way. But you can use Mailable inside a Notification class and use the notification instead of Mailable in a controller or service.

From the docs:

You may return a mailable object from the toMail method

public function toMail($notifiable)
{
    return (new Mailable($this->invoice))->to($this->user->email);
}