laravel-notification-channels / fcm

Firebase Cloud Messaging (FCM) notifications channel for Laravel
https://laravel-notification-channels.com/
MIT License
495 stars 127 forks source link

Overriding the `routeNotificationFcm()` method #210

Closed seunsekoni closed 3 weeks ago

seunsekoni commented 3 weeks ago

How can I override the routeNotificationFcm() method so that I can dynamically send notification to devices.

My architecture is that we save both web browser tokens and mobile device tokens on the same table and we use an identifier to identify if the token is a browser's or mobile.

The issue is that there's no way to dynamically call the mobile or device tokens from the method. The method just fetches all the user's tokens and send the notification. Can you suggest a way this can be done?

dwightwatson commented 3 weeks ago

I believe that the $notification is passed as the first argument to routeNotificationForFcm so you can inspect the notification class and make determinations on what tokens to return based upon that. You could either use different types of notifications or provide some interface on the notification to control the behaviour.