Skip to content

Commit e1aef8b

Browse files
authored
Pass notification to routeNotificationFor (#116)
As Laravel standard is to share notification instance with routeNotificationFor($notification) method, we can share it for Notifiable to check which phone number to use based on different notification class. #Reference https://laravel.com/docs/8.x/notifications#customizing-the-recipient
1 parent 509c768 commit e1aef8b

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/TwilioChannel.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(Twilio $twilio, Dispatcher $events)
4444
public function send($notifiable, Notification $notification)
4545
{
4646
try {
47-
$to = $this->getTo($notifiable);
47+
$to = $this->getTo($notifiable, $notification);
4848
$message = $notification->toTwilio($notifiable);
4949
$useSender = $this->canReceiveAlphanumericSender($notifiable);
5050

@@ -79,17 +79,18 @@ public function send($notifiable, Notification $notification)
7979
* Get the address to send a notification to.
8080
*
8181
* @param mixed $notifiable
82+
* @param Notification|null $notification
8283
*
8384
* @return mixed
8485
* @throws CouldNotSendNotification
8586
*/
86-
protected function getTo($notifiable)
87+
protected function getTo($notifiable, $notification = null)
8788
{
88-
if ($notifiable->routeNotificationFor(self::class)) {
89-
return $notifiable->routeNotificationFor(self::class);
89+
if ($notifiable->routeNotificationFor(self::class, $notification)) {
90+
return $notifiable->routeNotificationFor(self::class, $notification);
9091
}
91-
if ($notifiable->routeNotificationFor('twilio')) {
92-
return $notifiable->routeNotificationFor('twilio');
92+
if ($notifiable->routeNotificationFor('twilio', $notification)) {
93+
return $notifiable->routeNotificationFor('twilio', $notification);
9394
}
9495
if (isset($notifiable->phone_number)) {
9596
return $notifiable->phone_number;

0 commit comments

Comments
 (0)