Skip to main content

Notifications Module

Overview

The notification module provides event-driven alerts through two channels: in-app notifications (stored in database) and email notifications (sent via configured mail transport).

Scope

FeatureStatus
In-App Notifications✅ Implemented
Email Notifications✅ Implemented
Notification Settings (Admin)✅ Implemented
Unread Count / Badge✅ Implemented
Mark as Read (single & bulk)✅ Implemented
Push Notifications🔜 Future
SMS Notifications🔜 Future

Architecture

How Notifications Work

  1. A domain event occurs (e.g., employee submits self-assessment).
  2. The service layer dispatches a Laravel Notification to the appropriate recipients.
  3. Laravel routes the notification through configured channels (database, mail).
  4. The database channel creates a record in the notifications table.
  5. The mail channel sends an email via the configured SMTP transport.
  6. The frontend polls or checks for new notifications on page navigation.

Backend Components

ComponentPathPurpose
Notifications Dirapp/Notifications/Laravel Notification classes
Notification SettingsDatabase tablePer-event-type on/off toggles
Mail Templatesresources/views/mail/Email templates

Notification Classes

Each notification class implements:

  • via() — Returns channels (['database', 'mail'])
  • toArray() — Data stored in the notifications table
  • toMail() — Email content and template

Frontend Components

ComponentPathPurpose
Bell Dropdownsrc/components/notifications/Bell icon with unread count + dropdown
Settings Pageapp/dashboard/notification-settings/Admin notification configuration

Event Types

EventNotification ClassRecipients
Self-Assessment SubmittedKpiSelfAssessmentSubmittedAssigned reviewer
Manager Review SubmittedKpiManagerReviewSubmittedHR users
HR Review SubmittedKpiHrReviewSubmittedEmployee
Evaluation AcceptedKpiEvaluationAcceptedHR users
Evaluation DisputedKpiEvaluationDisputedHR users
Probation Review CreatedProbationReviewCreatedAssigned manager
Probation Review SubmittedProbationReviewSubmittedHR users
Probation Review OutcomeProbationReviewOutcomeManager

Data Model

Notifications Table (Laravel Default)

notifications (
id UUID PRIMARY KEY,
type VARCHAR, -- Notification class name
notifiable_type VARCHAR, -- 'App\Models\User'
notifiable_id BIGINT, -- User ID
data JSON, -- Notification payload
read_at TIMESTAMP NULL, -- NULL = unread
created_at TIMESTAMP,
updated_at TIMESTAMP
)

Notification Settings Table

notification_settings (
id BIGINT PRIMARY KEY,
event_type VARCHAR, -- Event identifier
channels JSON, -- ['database', 'mail']
is_active BOOLEAN, -- Master toggle
created_at TIMESTAMP,
updated_at TIMESTAMP
)

API Endpoints

MethodEndpointDescription
GET/api/notificationsList user's notifications
GET/api/notifications/unread-countGet unread notification count
POST/api/notifications/{id}/mark-readMark single notification as read
POST/api/notifications/mark-all-readMark all as read
GET/api/notification-settingsGet notification settings
PUT/api/notification-settingsUpdate notification settings

Email Configuration

Email notifications use Laravel's mail system. Configure in .env:

MAIL_MAILER=smtp
MAIL_HOST=localhost
MAIL_PORT=2525
MAIL_FROM_ADDRESS=hrms@kingrevolution.com
MAIL_FROM_NAME="King Revolution HRMS"

For local development, use smtp4dev to capture emails without sending them.