General — Settings & Platform Services
Overview
The General sub-module covers all platform-wide services that manage configuration, audit trails, approvals, assets, contacts, and master data. These are the foundational services that every domain module depends on.
What's Covered
| Service | Description |
|---|---|
| Settings Management | Key-value configuration with Redis caching and type casting |
| Activity Logging | Automatic audit trail via the HasLog trait |
| Approval Workflow | Polymorphic approval system for any model |
| Asset Management | File/media storage with local disk and ImageKit cloud |
| Contact Storage | Encrypted contact information with censorship support |
| Master Data | Genders, Ethnicities, Religions, Localizations |
Settings Management
Concept
The Setting model provides a centralized, cached key-value store. Every setting is identified by a triple of (module, group, key). Values are automatically type-cast when read and cached in Redis for 60 minutes.
Key methods:
Setting::get('module', 'group', 'key', $default)— Read with cachingSetting::updateOrCreate(...)— Write with automatic cache invalidation
Flowchart — Setting Read/Write Flow
The following flowchart illustrates how settings are read, cached, and written:
Explanation:
- On read, the system first checks Redis cache. If found, the cached value (with proper type casting) is returned immediately.
- On cache miss, the
settingstable is queried. The raw value is cast according to itstypecolumn. - The cast value is cached in Redis for 60 minutes, then returned.
- On write, all cached setting keys are invalidated to ensure consistency.
Activity Logging
The HasLog trait automatically records all creates, updates, and deletes for any model. It uses Eloquent event listeners and stores entries in the activity_logs table via a polymorphic relationship.
Explanation:
- The trait registers Eloquent event listeners for
created,updated, anddeleted. - On update, timestamp fields (
updated_at) are excluded. Only meaningful changes are logged. - The log includes the acting user, action type, description, old/new values, IP address, and user agent.
Approval Workflow
The Approval model provides a polymorphic approval system. Any model can have approvers defined by role name or specific user. The system supports configurable minimum approval counts.
Approver resolution:
- Role-based: Resolves all users with a given Spatie Role name
- User-based: Directly assigned to a specific user
Data Flow Diagram — Level 0 System Context
Activity Diagram — Setting Management Lifecycle
Database
Key Tables
| Table | Purpose | Unique Constraint |
|---|---|---|
settings | Key-value config store | (module, group, key) |
activity_logs | Audit trail | — (polymorphic) |
approvals | Workflow approvals | — (polymorphic) |
assets | File/media storage | — |
contacts | Encrypted contacts | (type, censored) |
Key Files
app/Models/Platform/
├── Setting/Setting.php # Cached key-value store
├── ActivityLog/ActivityLog.php # Polymorphic audit trail
├── Approval/Approval.php # Workflow approval system
├── Asset/Asset.php # File/media abstraction
├── Contact/Contact.php # Encrypted contacts
├── Gender/Gender.php # Gender master data
├── Ethnicity/Ethnicity.php # Ethnicity master data
├── Religion/Religion.php # Religion master data
└── Localization/Localization.php # Locale master data
app/Traits/Common/
├── HasLog.php # Auto-logging on events
├── HasAsset.php # Asset relationship
└── HasContact.php # Contact relationship
app/Filament/Clusters/SystemSettings/
└── Pages/
├── ManageGeneralSettings.php # General system settings
└── ManageMailSettings.php # Mail configuration
database/migrations/v1_0_0/
└── 001_migrate_platform.php # All platform tables