Skip to content

Notifications

sequence: Sender {
start
Sender -> Sender: centerNotification = createObject(CenterNotification)
Sender -> Sender: user.notify(centerNotification)
Sender -> ChannelManager: WebPushChannel.send(user, centerNotification)
ChannelManager -> WebPushChannel: WebPushChannel
WebPushChannel -> WebPushChannel: centerNotification.toWebPush()
WebPushChannel -> WebPushChannel: send
ChannelManager -> NotificationCenterChannel: NotificationCenterChannel.send(user, centerNotification)
NotificationCenterChannel -> NotificationCenterChannel: entry = centerNotification.toNotificationCenterEntry()
NotificationCenterChannel -> NotificationCenter: center.create(entry)
NotificationCenter -> NotificationCenter: Notification Center Stuff
NotificationCenter -> NotificationCenter: entry.save()
stop
}
$notification = new CenterNotification('Title', 'Message');
$notification->data(['key' => 'value']);
$user->notify($notification);

Updating notifications, where $id is the ID of the notification to update:

$notification = new CenterNotification('Updated title', 'Message');
$notification->updates($id); // Specify the notification that should be updated
$notification->data(['key' => 'value']);
$user->notify($notification);

The CenterNotification class. This is the class that should be interacted with when creating and sending notifications. It is not an Eloquent model. Rather, CenterNotification is sent to the NotificationCenterChannel and the WebPush channel classes, which transform the object into the data representation they need.

The NotificationCenterEntry class is an Eloquent model describing a stored notification with the ID from CenterNotification. It can be constructed by calling toNotificationCenterEntry on a CenterNotification. This model is managed by the NotificationCenter class, which is represented as a singleton with app(NotificationCenter::class).

The WebPushMessage class is used by the WebPushChannel and can be constructed by calling toWebPush on a CenterNotification.

The WorkflowNotification class is a basic model that is fed with data from action/notify workflow element. It can be transformed to a ToastMessage, a Mailable and to a CenterNotification.