Skip to content
Kona

Notifications

Implement Notifiable (routing per channel) and Notification (via, toMail, toArray), then send through NotificationSender.

class InvoicePaid : Notification() {
override fun via(notifiable: Notifiable) = listOf("mail", "database", "log")
override fun toMail(notifiable: Notifiable) = object : Mailable() { /* … */ }
override fun toArray(notifiable: Notifiable) = mapOf("status" to "paid")
}
app.resolve(NotificationSender::class.java).send(user, InvoicePaid())

Register MailServiceProvider then NotificationServiceProvider. Channels: mail (needs Mailer), database, log. When QueueServiceProvider is registered and a notification implements ShouldQueue, delivery goes through Bus.

DatabaseChannel stores [NotificationRecord] rows (id, type, data, notifiable, readAt, timestamps).

notifications.database.driver Behavior
memory (default) In-process store; optional JSON file via notifications.database.path
file / json Same as memory with a path when configured
database / cadence Cadence table (default notifications) when Database is bound
app.config.set("notifications.database.driver", "database")
app.config.set("notifications.database.table", "notifications")
app.register(CadenceServiceProvider())
app.register(NotificationServiceProvider())
val db = app.resolve(DatabaseChannel::class.java)
val unread = db.unread("user@example.com")
db.markAsRead(unread.first().id)
db.markAllAsRead("user@example.com")
DatabaseChannel db = app.resolve(DatabaseChannel.class);
db.markAllAsRead("user@example.com");

You can also construct DatabaseChannel(path) or DatabaseChannel(store) directly in tests.