# Notification Templates & Seeder Documentation
## 🎯 **Complete Notification Template System**
### **Overview**
A comprehensive notification template system with default content, seeder, and helper functions for managing all notification types across the application.
---
## 📋 **Available Templates**
### **🔔 Booking Notifications**
1. **Booking Confirmation** (`booking_confirmation_template`)
- Subject: Booking confirmation with booking number
- Content: Booking details, venue info, timing, next steps
2. **Booking Reminder** (`booking_reminder_template`)
- Subject: Reminder for upcoming booking
- Content: Booking details, arrival instructions, important notes
3. **Booking Cancellation** (`booking_cancellation_template`)
- Subject: Cancellation confirmation
- Content: Cancellation details, refund information
4. **Booking Update** (`booking_update_template`)
- Subject: Booking modification notification
- Content: Updated details, changes summary
5. **Urgent Booking** (`urgent_booking_template`)
- Subject: URGENT action required
- Content: Critical issues, required actions, contact info
### **💳 Payment Notifications**
1. **Payment Confirmation** (`payment_confirmation_template`)
- Subject: Payment processed successfully
- Content: Payment details, transaction ID, booking status
2. **Payment Request** (`payment_request_template`)
- Subject: Payment required for booking
- Content: Amount due, payment methods, due date, payment URL
3. **Payment Failed** (`payment_failed_template`)
- Subject: Payment processing failed
- Content: Failure details, retry options, troubleshooting
### **👤 Account Notifications**
1. **Welcome Email** (`welcome_email_template`)
- Subject: Welcome to the platform
- Content: Account details, getting started guide, benefits
2. **Email Verification** (`email_verification_template`)
- Subject: Verify email address
- Content: Verification code, verification URL, expiry info
3. **Password Reset** (`password_reset_template`)
- Subject: Reset password request
- Content: Reset link, security tips, expiry time
4. **Account Update** (`account_update_template`)
- Subject: Account information updated
- Content: Update details, security alert, recovery steps
5. **Account Delete** (`account_delete_template`)
- Subject: Account deletion confirmation
- Content: Deletion details, data retention, recovery info
### **👨💼 Admin Notifications**
1. **System Alert** (`system_alert_template`)
- Subject: System alert with severity level
- Content: Alert details, impact, actions, technical info
2. **Revenue Report** (`revenue_report_template`)
- Subject: Revenue report for period
- Content: Financial summary, metrics, recommendations
### **📢 Marketing Notifications**
1. **Promotional Offer** (`promotional_offer_template`)
- Subject: Special offer announcement
- Content: Offer details, benefits, promo code, call-to-action
2. **New Venue Announcement** (`new_venue_announcement_template`)
- Subject: New venue opening
- Content: Venue details, highlights, opening offers
3. **Seasonal Campaign** (`seasonal_campaign_template`)
- Subject: Seasonal special campaign
- Content: Seasonal highlights, offers, countdown, testimonials
---
## 🌱 **Seeder Implementation**
### **File Location**
```
database/seeders/NotificationContentSeeder.php
```
### **Seeder Features**
- **Complete Default Content**: Professional templates for all 20 notification types
- **JSON Format**: Structured data with subject and content
- **Variable Placeholders**: Dynamic content using `{variable}` syntax
- **Multi-tenant Support**: Company-specific templates
- **Fallback Support**: Default templates when custom ones aren't set
### **Running the Seeder**
```bash
# Run all seeders
php artisan db:seed
# Run only notification seeder
php artisan db:seed --class=NotificationContentSeeder
# Fresh database with all seeders
php artisan migrate:fresh --seed
```
### **Seeder Structure**
```php
// Each template stored as JSON in settings table
[
'subject' => 'Email Subject Line',
'content' => 'Email content with {variables}',
]
```
---
## 🔧 **Helper Functions**
### **File Location**
```
app/Helpers/NotificationTemplateHelper.php
```
### **Key Methods**
#### **Get Template Content**
```php
use App\Helpers\NotificationTemplateHelper;
// Get template with variables
$template = NotificationTemplateHelper::getTemplate(
'booking_confirmation_template',
[
'customer_name' => 'John Doe',
'booking_number' => 'BK-2024-001',
'venue_name' => 'Beach Resort',
'booking_date' => '2024-12-25',
'booking_time' => '14:00',
'company_name' => 'ZapaziMe'
]
);
// Returns: ['subject' => '...', 'content' => '...']
```
#### **Preview Template**
```php
// Preview with sample data
$preview = NotificationTemplateHelper::previewTemplate('booking_confirmation_template');
```
#### **Check Template Exists**
```php
if (NotificationTemplateHelper::templateExists('booking_confirmation_template')) {
// Template exists
}
```
#### **Get All Templates**
```php
$templates = NotificationTemplateHelper::getAvailableTemplates();
```
---
## 📝 **Variable System**
### **Supported Variables**
Each template supports dynamic variables using `{variable_name}` syntax:
#### **Common Variables**
- `{customer_name}` - Customer's full name
- `{customer_email}` - Customer's email address
- `{company_name}` - Your company name
- `{booking_number}` - Unique booking identifier
- `{venue_name}` - Name of the venue
- `{booking_date}` - Booking date
- `{booking_time}` - Booking time
- `{total_amount}` - Total booking amount
#### **Payment Variables**
- `{payment_amount}` - Payment amount
- `{payment_date}` - Payment processing date
- `{payment_method}` - Payment method used
- `{transaction_id}` - Transaction identifier
#### **Account Variables**
- `{verification_code}` - Email verification code
- `{verification_url}` - Verification link
- `{reset_url}` - Password reset link
- `{expiry_hours}` - Link/code expiry time
#### **Admin Variables**
- `{alert_type}` - Type of system alert
- `{severity}` - Alert severity level
- `{report_period}` - Revenue report period
- `{total_revenue}` - Total revenue amount
### **Variable Replacement**
The helper automatically replaces both `{variable}` and `#{variable}` formats:
```php
// Both formats work
Welcome {customer_name}!
Your booking #{booking_number} is confirmed.
```
---
## 🎨 **Template Customization**
### **Admin Panel Integration**
Templates can be customized through the admin panel:
1. Go to Settings → Notification Settings
2. Navigate to "Notification Templates" tab
3. Find the desired notification type
4. Toggle enable/disable
5. Edit custom content in the textarea
6. Save changes
### **Custom Template Storage**
- **Location**: `settings` table
- **Group**: `notifications`
- **Format**: JSON with `subject` and `content`
- **Company-specific**: Multi-tenant support
### **Template Priority**
1. **Custom Template** (if set in admin panel)
2. **Seeder Default** (from NotificationContentSeeder)
3. **Helper Fallback** (basic default template)
---
## 🔌 **Integration Examples**
### **In Notification Classes**
```php
use App\Helpers\NotificationTemplateHelper;
class BookingConfirmationNotification extends Notification
{
public function toMail($notifiable)
{
$template = NotificationTemplateHelper::getTemplate(
'booking_confirmation_template',
[
'customer_name' => $notifiable->name,
'booking_number' => $this->booking->booking_number,
'venue_name' => $this->booking->venue->name,
'booking_date' => $this->booking->date->format('Y-m-d'),
'booking_time' => $this->booking->time,
'company_name' => config('app.name')
]
);
return (new MailMessage)
->subject($template['subject'])
->markdown('emails.custom', ['content' => $template['content']]);
}
}
```
### **Custom Email View**
```blade
<!-- resources/views/emails/custom.blade.php -->
@component('mail::message')
{!! nl2br($content) !!}
@endcomponent
```
### **Controller Usage**
```php
public function sendCustomNotification()
{
$template = NotificationTemplateHelper::getTemplate(
'promotional_offer_template',
[
'customer_name' => $user->name,
'offer_title' => 'Summer Special',
'discount_percentage' => '25',
'promo_code' => 'SUMMER25',
'company_name' => 'ZapaziMe'
]
);
Mail::to($user->email)->send(new CustomMail($template));
}
```
---
## 🛠 **Advanced Features**
### **Multi-tenant Templates**
```php
// Company-specific template
$template = NotificationTemplateHelper::getTemplate(
'booking_confirmation_template',
$variables,
$company_id // Specific company ID
);
```
### **Template Validation**
```php
// Check if template exists before using
if (NotificationTemplateHelper::templateExists($templateKey)) {
$template = NotificationTemplateHelper::getTemplate($templateKey, $variables);
}
```
### **Error Handling**
The helper includes comprehensive error handling:
- Invalid JSON format handling
- Missing template fallbacks
- Logging of template errors
- Graceful degradation to defaults
---
## 📊 **Template Management**
### **Template Storage Structure**
```sql
-- Settings table structure
CREATE TABLE settings (
id BIGINT PRIMARY KEY,
name VARCHAR(255), -- Template key (e.g., 'booking_confirmation_template')
group VARCHAR(255), -- 'notifications'
payload JSON, -- {'subject': '...', 'content': '...'}
company_id BIGINT, -- Multi-tenant support
active BOOLEAN DEFAULT TRUE,
created_at TIMESTAMP,
updated_at TIMESTAMP
);
```
### **Template Retrieval Logic**
1. Check for company-specific custom template
2. Fall back to global custom template
3. Use seeder default template
4. Use helper fallback template
---
## 🎯 **Best Practices**
### **Template Design**
- **Clear Subject Lines**: Include key identifiers (booking numbers, dates)
- **Personalization**: Use customer name and relevant details
- **Call-to-Action**: Clear next steps and contact information
- **Professional Tone**: Consistent brand voice
- **Mobile-Friendly**: Responsive formatting
### **Variable Usage**
- **Consistent Naming**: Use descriptive variable names
- **Complete Coverage**: Include all necessary variables
- **Fallback Values**: Provide defaults for missing variables
- **Validation**: Check required variables before sending
### **Performance**
- **Template Caching**: Cache parsed templates
- **Lazy Loading**: Load templates only when needed
- **Batch Processing**: Handle multiple notifications efficiently
---
## 🔄 **Maintenance & Updates**
### **Adding New Templates**
1. Add template to `NotificationContentSeeder`
2. Update `getAvailableTemplates()` in helper
3. Add to admin panel settings
4. Update notification classes
5. Test with sample data
### **Template Updates**
1. Update seeder with new default content
2. Run seeder to update defaults
3. Communicate changes to administrators
4. Update documentation
### **Monitoring**
- Log template errors and warnings
- Monitor template usage statistics
- Track custom template adoption
- Review template performance
---
## 🎉 **Benefits**
### **For Administrators**
- **Easy Customization**: No coding required
- **Professional Templates**: High-quality defaults
- **Brand Consistency**: Unified messaging
- **Multi-language Ready**: Translation-friendly
### **For Developers**
- **Centralized Management**: Single source of truth
- **Flexible System**: Extensible architecture
- **Error Handling**: Robust fallbacks
- **Testing Support**: Preview functionality
### **For Users**
- **Personalized Content**: Relevant information
- **Professional Communication**: Quality messaging
- **Clear Instructions**: Actionable content
- **Consistent Experience**: Unified brand voice
---
**This comprehensive notification template system provides professional, customizable, and maintainable email content for all application notifications while ensuring brand consistency and user engagement!** 🎯