You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I find I need to do a lot of on demand notifications (not tied to a notifiable entity). This can be done though the Notification facade passing in a route method (https://laravel.com/docs/8.x/notifications#on-demand-notifications). However that would require me to define routing everywhere I dispatch a notification.
I was thinking it would be nice to be able to put that routing logic in the notification class itself and just call Notification::notify(new SomeNotification($data));. I would use this a lot for slack messages to myself when certain events happen in app. There is only ever one way to route that and so I would like to be able to add a method to the notification to define that like:
I haven't looked deep into how Laravel's notifications work but I'd be open to looking into it and making a PR to do this if its something others agree would make sense, or maybe I just have a unique use-case. I am thinking if you define a route() method when calling the notification it would use that, but if not it would look for something like a "route(Driver)" method inside the notification class.
On that same note, I was also thinking of adding a global notification helper so I could just call notify(new SomeNotification($data)); instead of importing the notification facade and calling Notification::notify(new SomeNotification($data));. Assuming that's not going to cause any naming collisions.
Interested in feedback if this would be worth my time to put up a PR for.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I find I need to do a lot of on demand notifications (not tied to a notifiable entity). This can be done though the Notification facade passing in a
route
method (https://laravel.com/docs/8.x/notifications#on-demand-notifications). However that would require me to define routing everywhere I dispatch a notification.I was thinking it would be nice to be able to put that routing logic in the notification class itself and just call
Notification::notify(new SomeNotification($data));
. I would use this a lot for slack messages to myself when certain events happen in app. There is only ever one way to route that and so I would like to be able to add a method to the notification to define that like:public function routeSlack()
{
return 'https://hooks.slack.com/...';
}
I haven't looked deep into how Laravel's notifications work but I'd be open to looking into it and making a PR to do this if its something others agree would make sense, or maybe I just have a unique use-case. I am thinking if you define a
route()
method when calling the notification it would use that, but if not it would look for something like a "route(Driver)" method inside the notification class.On that same note, I was also thinking of adding a global notification helper so I could just call
notify(new SomeNotification($data));
instead of importing the notification facade and callingNotification::notify(new SomeNotification($data));
. Assuming that's not going to cause any naming collisions.Interested in feedback if this would be worth my time to put up a PR for.
Beta Was this translation helpful? Give feedback.
All reactions