Skip to content

Commit d6242ef

Browse files
committed
use routeNotificationFor to retrieve mail, if to's are not set
1 parent 324150f commit d6242ef

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/SendGridChannel.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,22 @@ public function send($notifiable, Notification $notification)
3333
throw new Exception('You must implement toSendGrid in the notification class for SendGrid channel.');
3434
}
3535

36+
/**
37+
* @var SendGridMessage
38+
*/
3639
$message = $notification->toSendGrid($notifiable);
3740

41+
if (empty($message->from)) {
42+
$message->from(
43+
config('mail.from.address'),
44+
config('mail.from.name')
45+
);
46+
}
47+
48+
if (empty($message->tos)) {
49+
$message->to($notifiable->routeNotificationFor('mail'));
50+
}
51+
3852
if (! ($message instanceof SendGridMessage)) {
3953
throw new Exception('toSendGrid must return an instance of SendGridMessage.');
4054
}

src/SendGridMessage.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function from($email, $name)
6969
* @param array $data
7070
* @return $this
7171
*/
72-
public function to($email, $name, $data = [])
72+
public function to($email, $name = null, $data = [])
7373
{
7474
$this->tos = array_merge($this->tos, [new To($email, $name, $data)]);
7575

@@ -88,14 +88,6 @@ public function payload($payload)
8888
*/
8989
public function build(): Mail
9090
{
91-
if (! $this->from) {
92-
// If from is not defined, use the values set in Laravel config
93-
$this->from(
94-
config('mail.from.address'),
95-
config('mail.from.name')
96-
);
97-
}
98-
9991
$email = new Mail(
10092
$this->from,
10193
$this->tos

0 commit comments

Comments
 (0)