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.

bdg_items

Badge configurations for visual indicators on notifications.

action_items

Action button definitions with navigation types and parameters.

notification_templates

Reusable templates for multi-channel notifications.

notif_reads

Tracks which users have read which notifications (one record per user per notification).

πŸ’» 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
}