Skip to content

Commit

Permalink
Pass notification to routeNotificationFor (#116)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
skybitbbsr authored Mar 2, 2021
1 parent 509c768 commit e1aef8b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/TwilioChannel.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function __construct(Twilio $twilio, Dispatcher $events)
public function send($notifiable, Notification $notification)
{
try {
$to = $this->getTo($notifiable);
$to = $this->getTo($notifiable, $notification);
$message = $notification->toTwilio($notifiable);
$useSender = $this->canReceiveAlphanumericSender($notifiable);

Expand Down Expand Up @@ -79,17 +79,18 @@ public function send($notifiable, Notification $notification)
* Get the address to send a notification to.
*
* @param mixed $notifiable
* @param Notification|null $notification
*
* @return mixed
* @throws CouldNotSendNotification
*/
protected function getTo($notifiable)
protected function getTo($notifiable, $notification = null)
{
if ($notifiable->routeNotificationFor(self::class)) {
return $notifiable->routeNotificationFor(self::class);
if ($notifiable->routeNotificationFor(self::class, $notification)) {
return $notifiable->routeNotificationFor(self::class, $notification);
}
if ($notifiable->routeNotificationFor('twilio')) {
return $notifiable->routeNotificationFor('twilio');
if ($notifiable->routeNotificationFor('twilio', $notification)) {
return $notifiable->routeNotificationFor('twilio', $notification);
}
if (isset($notifiable->phone_number)) {
return $notifiable->phone_number;
Expand Down

0 comments on commit e1aef8b

Please sign in to comment.