Notification System
Complete guide to notification items, badges, actions, and templates
5 Tables
Badges
Actions
Templates
π Overview
The Notification System provides a flexible, multi-channel notification framework with customizable badges, actions, and templates. Notifications can be displayed with visual indicators and include action buttons for user interaction.
- Rich Notifications - Support for badges, actions, and custom content
- Badge Configurations - Visual indicators with customizable styles
- Action Buttons - Primary and secondary actions with navigation
- Templates - Reusable notification templates for different channels
- Read Tracking - Track which users have read which notifications
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β NOTIFICATION SYSTEM β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββ β
β β notif_items ββββββΆβ bdg_items β βaction_items β β
β β β β (Badges) β β (Buttons) β β
β β - notif_id β β β β β β
β β - bdg_id FK β β - bdg_id β β - act_id β β
β β - pri_id FK ββββββΆβ - type β β - type β β
β β - sec_id FK β β - text β β - nav_type β β
β β - inst_id FK β β - icon β β - base_url β β
β ββββββββββββββββ β - bg_color β β - params β β
β β ββββββββββββββββ ββββββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββ β
β βnotif_reads βββββ app_users.user_id β
β β(Read Trackingβ β
β β per user) β β
β β β β
β β - notif_id β β
β β - user_id β β
β β - read_at β β
β ββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β notification_templates β β
β β (Multi-channel Templates) β β
β β β β
β β - template_key (Unique identifier) β β
β β - placeholders (e.g., {username}, {amount}) β β
β β - content (Template body with {placeholders}) β β
β β - channel_type (push, email, sms, in_app) β β
β β - is_active (Enable/disable) β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
β NOTIFICATION FLOW: β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β 1. Create notification with notif_id β β
β β 2. Configure badge (optional) - visual indicator β β
β β 3. Configure actions (optional) - primary/secondary buttons β β
β β 4. Set visibility status & availability β β
β β 5. Track reads per user via notif_reads β β
β β 6. Use templates for consistent multi-channel messages β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π Table Reference
notif_items
Core notification definitions with content, badges, and actions.
| Field | Type | Attributes | Description |
|---|---|---|---|
id | BIGINT | PK, Auto Increment | Primary key |
notif_id | VARCHAR(50) | UNIQUE | Public notification identifier |
source | VARCHAR(50) | NOT NULL | Notification source (system, user, order) |
status | INT | Default: 1 | 0=hidden, 1=visible |
type | VARCHAR(50) | NOT NULL | info, warning, success, error |
variant | VARCHAR(50) | Default: simple | simple, actionable, rich |
title | VARCHAR(255) | NOT NULL | Notification title |
description | TEXT | NULLABLE | Notification body text |
bdg_id | VARCHAR(50) | FK, NULLABLE | References bdg_items.bdg_id |
inst_id | INT | FK, NULLABLE | Related instrumentation ID |
pri_label | VARCHAR(50) | NULLABLE | Primary action button label |
pri_id | VARCHAR(50) | FK, NULLABLE | References action_items.act_id |
pri_variant | VARCHAR(50) | NULLABLE | Primary button style |
sec_label | VARCHAR(50) | NULLABLE | Secondary action label |
sec_id | VARCHAR(50) | FK, NULLABLE | References action_items.act_id |
sec_variant | VARCHAR(50) | NULLABLE | Secondary button style |
notif_from | VARCHAR(100) | NULLABLE | Sender identifier |
notif_cnd | JSON | NULLABLE | Display conditions |
is_ava | BOOLEAN | Default: true | Is available for display |
custom | JSON | NULLABLE | Custom metadata |
bdg_items
Badge configurations for visual indicators on notifications.
| Field | Type | Attributes | Description |
|---|---|---|---|
id | BIGINT | PK, Auto Increment | Primary key |
bdg_id | VARCHAR(50) | UNIQUE | Badge identifier |
type | VARCHAR(50) | NOT NULL | number, text, dot |
text | VARCHAR(20) | NULLABLE | Text for text badges |
number | INT | NULLABLE | Number for number badges |
icon | VARCHAR(50) | NULLABLE | Icon identifier |
size | VARCHAR(20) | Default: md | xs, sm, md, lg |
bg_color | VARCHAR(20) | NULLABLE | Background color |
border_color | VARCHAR(20) | NULLABLE | Border color |
is_round | BOOLEAN | Default: false | Rounded corners |
is_hover | BOOLEAN | Default: false | Show on hover |
is_dot | BOOLEAN | Default: false | Dot style indicator |
is_active | BOOLEAN | Default: true | Badge availability |
action_items
Action button definitions with navigation types and parameters.
| Field | Type | Attributes | Description |
|---|---|---|---|
id | BIGINT | PK, Auto Increment | Primary key |
act_id | VARCHAR(50) | UNIQUE | Action identifier |
type | VARCHAR(50) | NOT NULL | navigate, execute, dismiss |
nav_type | VARCHAR(20) | Default: internal | internal, external |
base_url | VARCHAR(500) | NOT NULL | URL with {placeholders} |
params | JSON | NULLABLE | URL parameters |
notification_templates
Reusable templates for multi-channel notifications.
| Field | Type | Attributes | Description |
|---|---|---|---|
id | BIGINT | PK, Auto Increment | Primary key |
template_key | VARCHAR(100) | UNIQUE | Template identifier |
placeholders | VARCHAR(255) | NULLABLE | Comma-separated placeholder names |
content | TEXT | NOT NULL | Template body with {placeholders} |
channel_type | VARCHAR(20) | Default: push | push, email, sms, in_app |
description | TEXT | NULLABLE | Template description |
is_active | BOOLEAN | Default: true | Template availability |
notif_reads
Tracks which users have read which notifications (one record per user per notification).
| Field | Type | Attributes | Description |
|---|---|---|---|
id | BIGINT | PK, Auto Increment | Primary key |
notif_id | VARCHAR(50) | FK | References notif_items.notif_id |
user_id | VARCHAR(32) | FK | References app_users.user_id |
read_at | TIMESTAMP | NULLABLE | Read timestamp |
π» Usage Examples
// Create a notification with badge and actions
$notification = NotifItem::create([
'notif_id' => 'order_12345_shipped',
'source' => 'order',
'type' => 'success',
'variant' => 'actionable',
'title' => 'Order Shipped!',
'description' => 'Your order #12345 has been shipped.',
'bdg_id' => 'new_badge', // Shows "New" indicator
'pri_label' => 'Track Order',
'pri_id' => 'track_order_action',
'sec_label' => 'View Details',
'sec_id' => 'view_details_action',
'notif_from' => 'orders-system',
'is_ava' => true,
]);
// Create a badge
$badge = BdgItem::create([
'bdg_id' => 'new_badge',
'type' => 'text',
'text' => 'New',
'size' => 'sm',
'bg_color' => '#10B981',
'is_active' => true,
]);
// Create an action
$action = ActionItem::create([
'act_id' => 'track_order_action',
'type' => 'navigate',
'nav_type' => 'internal',
'base_url' => '/orders/{order_id}/track',
'params' => ['order_id' => '12345'],
]);
// Mark notification as read for user
NotifRead::markAsRead('order_12345_shipped', 'ABC123');
// Check if user has read notification
$isRead = NotifRead::isReadByUser('order_12345_shipped', 'ABC123');
// Use template for email
$template = NotificationTemplate::where('template_key', 'order_shipped_email')
->where('channel_type', 'email')
->first();
$emailContent = $template->render([
'username' => 'John Doe',
'order_id' => '12345',
'tracking_link' => 'https://track.example.com/12345',
]);
// Output: "Hello John Doe, Your order #12345 has been shipped..."
// Get notification with relationships
$notification = NotifItem::with('badge', 'primaryAction', 'secondaryAction')
->where('notif_id', 'order_12345_shipped')
->first();
// Check if notification is visible
if ($notification->isVisible()) {
// Display notification
}