I am developing a fairly simple application, where I want my users to be able to subscribe to notifications. So the system should:
- Send notifications when a certain event they are subscribed to happens.
- Send notifications to the channels they have selected (email or slack)
Below is an example of different notifications they each user can subscribe to.
I am wondering how to do this using Laravel. My first idea was to:
- Create a
notificationsJSON column on theuserstable, and store it like (probably using the learnings from the Managing Mass User Settings lesson.)
{
"todo": {
"assigned": [
{
"email": true,
"slack": true
}
],
"mentioned": [
{
"email": true,
"slack": true
}
]
},
"project": {
"created": [
{
"email": true,
"slack": true
}
]
}
}
However, I am unsure if this is good practice. Further, I am also a unsure on how to actually send out the notifications dynamically.
For sending it out, I want to use Laravels notification system:
Notification::send($user, new TodoCreated($todo));
I am not sure if this is the best way, or if it makes more sense to use an Event/Listener setup? A
Also, can I utilize the via() method on the Notification class to dynamically specify the channels according to the user settings?
Any input would be greatly appreciated.
