I'm building a SAAS and I want each tenant to have their own queue for notifications. I have a notification class that implements Illuminate\Contracts\Queue\ShouldQueue and I send the notification like this
$user->notify($notification);
But I haven't found a way to specify the queue that I want the notification to be pushed to. I know that jobs can be pushed to specific queues with onQueue:
ProcessPodcast::dispatch($podcast)->onQueue('tenant1');
But is it possible to do something like this for queueable notifications as well?
Since your notification should use the Illuminate\Bus\Queueable trait you can simply set the $queue property of the object. There's a helper function for it:
$notification->onQueue('tenant1');
$user->notify($notification);
Related
Normally when sending notifications in Laravel you send to a class with a Notifiable trait that defines "who" the notification is going to by the instance of the class. Such as with the User model.
I have a use case to send a notification to myself (the admin) and I don't have an entry in the User model.
Laravel does allow the use of the route() method using the Notification facade such as
Notification::route('email', 'admin#myapp.example')->notify(new SomeLaravelNotification());
However imo that's kinda verbose, is there a way to wrap the routing logic into the Notification class so I can just call something like
Notification::send(new SomeLaravelNotification());
Then I could have the routing logic as part of the SomeLaravelNotification class?
Is it possible to create/send notification(s) to all users when there is new announcement.
I want all users to be notified using the database notification.
Since most of the tutorials I have seen are all email notification, is this possible? Please attach links or any idea on how I could implement this.
Literally in the documentation:
Alternatively, you may send notifications via the Notification facade.
This is useful primarily when you need to send a notification to
multiple notifiable entities such as a collection of users. To send
notifications using the facade, pass all of the notifiable entities
and the notification instance to the send method:
Notification::send($users, new InvoicePaid($invoice));
So yes, you can send to all user by getting them from the database and sending a notification using the facade.
For example:
Notification::send(User::all(), new InvoicePaid($invoice));
I am writing an external application that uses REST to communicate with open-daylight. I need to get a notification whenever a new communication between two nodes is needed.
I've checked how to subscribe for event notification in the following link. But I am not sure if this is possible for a packet_in event.
Is it possible to get a notification of the new connection packet_in, with/without some information about the packet?
What would be the path used to create-data-change-event-subscription? also, how can I check all available events and paths that I can make use of?
I believe the "packet_in" event is a yang notification however the REST notification subscription mechanism is for data change notifications. Unfortunately there is no mechanism currently (that I know of) to subscribe to yang notifications over rest.
I am a little confused about whether to use Laravel's Notification or Mailable class. From what I understand, Mailables are used to send only emails whereas Notifications can be used to send emails and sms. In my application, I dont have plans to send sms notifications for now, so I am confused if I should just use the Mailable class in this case. My questions are:
If I am only going to be sending emails notifications, is it
better for me to use Mailables instead of Notifications?
If each emails have different html layout, then would Mailable be
the better option?
Even if all emails are Notification emails in nature, does it still make
sense to send them using Mailables instead of Notifications?
Can someone tell me the main difference between these 2 and how should we decide on which method to choose when sending emails in Laravel 5.3.
Although it is not in the documentation, as of Laravel 5.3.7, the Notifications mail channel can work with Mailable objects in addition to the notification MailMessage objects.
Therefore, you can create all your emails as Mailable objects, and if you decide to send them via Notifications, you would just have your toMail() method return the Mailable objects you've already made.
Yes, definitively, if each email layout is different, you should use Mailable
Mailable is the new way to send emails, easier than before. More customizable than Notifications.
Notification is very nice if you want to send a predefined layout in differents channel ( Mail, SMS, Slack, etc )
You can customize notifications layout, but having 1 layout by notification is going to get more difficult... it is just not the use case for notifications
To create a topic for an event I need to declare this in my conf/MyEvents.groovy file as follows:
events = {
"topicName" browser: true
}
I am wanting to use the server push for two things, pushing chat messages to a client and also for pushing notifications to a client.
Using the former as an example, I will need to create a new Topic for each conversation that is instantiated in the chat system at runtime, so that messages can be pushed to each of the conversation participants, so along the lines of
new Event(topic:'anotherTopicName',...)
which will allow me to call from a service :
import grails.events.*
class MyService {
def doSomething(){
...
event(topic:'anotherNewTopic', data:data)
}
}
Is there a method that will allow me to create a new Event topic? Or is there another way to implement this using Events Push
I've just done something similar. I needed to show some notifications based on the user that had logged in, so I set this in MyEvents.groovy:
events = {
'newNotification_*' browser:true
}
And when I need to send the notification:
event topic:"newNotification_${userId}",data:n
Then in my browser I can listen to those notifications with something similar to this:
grailsEvents.on("newNotification_"+myUser,function(data){