1 year ago

How to route notifications based on the notification being sent

Posted 1 year ago by freekmurze

Sending notifications to a single webhook is quite easy. Just add a function the notifiable. The docs contain this example:

public function routeNotificationForSlack()
    return $this->slack_webhook_url;

This is good if all notifications should be send via the same slack webhook. But image some notifications should be send to another webhook on the notifiable. I'd like to be able to do this:

public function routeNotificationForSlack($notification)
    if ($notification instanceof MySpecialSnowflakeNotification) {
        return $this->alternative_slack_webhook;
    return $this->slack_webhook;

Unfortunately the notification isn't being passed to routeNotificationForSlack atm.

What is the easiest way to achieve that behaviour?

Please sign in or create an account to participate in this conversation.