-
Notifications
You must be signed in to change notification settings - Fork 28
[Proposal] Ability to define Notifications broadcast channel name #202
Comments
You can do this by returning a custom name from the |
@michaeldyrynda That is correct. But, I am talking about broadcasts from notifications, not events. The channel is set via the |
Ah yes of course. I suppose it would be trivial to add a It makes sense to have a consistent API. |
I created an issue for this a couple weeks ago, but I'm glad I'm not the only one who sees limitations with this design. |
@fgambino sorry, I missed that. I think your issue title might be poorly named, and possibly why it hasn't gained traction. "Allow custom notification type and channel names". Now, I see from the issue content, that you are actually wanting custom broadcast notification channel names, not notification channel names. |
@mikemclin no apology necessary. I can definitely see the confusion there. We can continue discussion in this issue! What if a |
I think the The biggest issue I have with not being able to specify a notification channel name is that it creates overhead for every additional channel I need to listen to; for example if I am listening to 30 widgets that's 30 channel auth callbacks. I think a common approach would be to broadcast all/some activity onto the current User channel and delegate it from there. I'm not convinced that this is a great design pattern either, but it has to be better than dozens of auth callbacks. |
Is there a current workaround for this? |
Isn' this what the |
This is still unsolved: it is possible to overwrite the name of the channel that a Notification is broadcasting on. However, it is not possible to overwrite the name of the event that the Notification is sending. The code for overriding this on an Event with The class where In fact, if one adds the following code to the class: public function broadcastAs()
{
return 'lol';
} A new event with the name I'll keep looking, but currently I see no way to configure this from the Notification. @Uruloke: |
You can do this by extending the broadcasters broadcast method, so you have a custom broadcaster driver which extend eg. PusherBroadcsster and overrides the data sent to the parent broadcast method. It's a few lines of codes, and works great. |
@Uruloke: You sir, are a genius! With my new custom broadcast driver I can now add a |
@SvenSchoene, no problem, had that same problem and spend some time decoding how the framework did it so I could customize it. @ALL: Anyone else interested in this feature, because we should be able to quickly create a pull request for this. |
@SvenSchoene you can define event name since v5.6.4 just return custom event name in I suppose this issue could be closed since all the questions which were raised here are solved. |
@a-komarev Absolutely perfect, thx! 👍 |
Hello @SvenSchoene could you send an example of this solution: "You sir, are a genius! With my new custom broadcast driver I can now add a broadcastAs()-method on my Notifications. Thank you very much!" Because, I couldn't make it. Thanks a lot |
@cadukiz read two coments above: #202 (comment) |
@a-komarev Thanks for the answer, but I need to change the broadcast event name from BroadcastNotificationCreated to MyNewEvent using broadcastAs() method. But from Notification. It was made : laravel/framework@6f28b66 But overwritten again with broadcastType(). My suggestion: keep both: |
public function broadcastAs()
} |
I have the same problem here too +1 |
@taylorotwell @antonkomarev what happened? |
@OleksandrVladymyrov method was renamed later laravel/framework@4227bd7 |
Same problem here. I'd like to change the What we can do currently is only change the When we broadcast from an Event in the app\Events folder, the name of the Event is the event itself, but there's no |
a quick fix for this, until the patch is accepted. exclude the current implementation then import yours "autoload": {
"exclude-from-classmap": [
"vendor/laravel/framework/src/Illuminate/Notifications/BroadcastNotificationCreated.php"
],
"psr-4": {
"App\\": "app/",
"Illuminate\\Notifications\\": "app/libs/Illuminate/Notifications/"
}
}, cp vendor/laravel/framework/src/Illuminate/Notifications/BroadcastNotificationCreated.php app/libs/Illuminate/Notifications/ then add this to app/libs/Illuminate/Notifications/BroadcastNotificationCreated.php //patch
public function broadcastAs()
{
if (method_exists($this->notification, 'broadcastAs')) {
return $this->notification->broadcastAs();
}
return get_class($this);
}
|
Alternatively you can just override the 'broadcastOn' method in the Notification class. |
Hi All, I spent hours yesterday trying to figure this out as well as I am trying to implement the broadcastAs in my Notification because it keeps sending down the BroadcastCreatedNotification class name but I want to customize it like I do for my other messages (that are being sent not through the notification system). After looking through this thread, at this point is there any solution or workarounds? I appreciate your response as I new to Laravel (6 months) and learning as I go. Have a great day. |
Hi, Do you think you might take a minute and provide a code snippet on the few lines of code that would allow me to extend the broadcaster driver? This is exactly what I need. Thanks! |
Is there any way to just use the ShouldBroadcastNow on notification since i cannot extend BroadcastNotificationCreated event ? |
I isn't solved yet :( , how can we extend the broadcast driver? @olivernybroe |
Damn, 4 years and we still cannot change the notification class event name from |
So, there was a problem reported 4 years ago, it was fixed at some point, and then un-fixed and has been staying like that since...? In what case does it make sense to send the event name as |
I agree that this should be reopened. What good is it to have the ability to override a Broadcast Event Name from Events but not from a Notification? Functionality should be leveraged between the two use cases. |
Currently the Notifications broadcast channel broadcasts to a dot-separated, capitalized version of the notifiable's namespace (e.g.
App.User
). However all of the example channel names in the docs seem to follow a lowercased basename format (e.g.user
).Obviously most people will want a consistent naming strategy for their channel names. Personally, I prefer the convention in the docs, because my client app doesn't need to know about my model paths in my API.
Anyways, it would be great if there was a hook of some sort, so we could set the channel name for a notification.
The text was updated successfully, but these errors were encountered: