# Content Management System (CMS)

## Overview
A complete CMS has been implemented for Flat Line, allowing administrators to manage all website pages including Help Center, Contact Us, FAQ, Terms of Service, and Privacy Policy through the admin dashboard.

## Features

### 1. Database Structure
- **Table**: `pages`
- **Columns**:
  - `id` - Primary key
  - `slug` - Unique URL identifier (e.g., 'help-center', 'faq')
  - `title` - Page title
  - `content` - HTML content
  - `meta_data` - JSON field for additional data
  - `is_active` - Boolean to show/hide pages
  - `created_at` / `updated_at` - Timestamps

### 2. Default Pages Created
The following pages are automatically seeded:

1. **Help Center** (`/page/help-center`)
   - Getting Started
   - Account Management
   - Transactions

2. **Contact Us** (`/page/contact-us`)
   - Email, Phone, Office Hours
   - Address information

3. **FAQ** (`/page/faq`)
   - Common questions and answers
   - Transaction times, payment methods, security

4. **Terms of Service** (`/page/terms-of-service`)
   - Acceptance of Terms
   - Use License
   - User Account
   - Transactions
   - Fees and Charges
   - Limitation of Liability

5. **Privacy Policy** (`/page/privacy-policy`)
   - Information Collection
   - How We Use Information
   - Information Sharing
   - Data Security
   - Cookies
   - User Rights

### 3. Admin Dashboard Integration

#### Navigation
- New "Pages" menu item added to admin sidebar under "System" section
- Located between "Settings" and "Logout"
- Icon: Document/file icon

#### Pages Management View (`/admin/pages`)
- Lists all pages in a table format
- Shows: Title, Slug, Status (Active/Inactive), Last Updated
- Actions: View (opens page in new tab), Edit

#### Edit Page View (`/admin/pages/{id}/edit`)
- **Page Title**: Editable text field
- **Page Slug**: Display only (cannot be changed to maintain link integrity)
- **Page Content**: Large textarea with HTML support
- **Status Toggle**: Checkbox to activate/deactivate page
- **Actions**:
  - Cancel (returns to pages list)
  - Preview Page (opens page in new tab)
  - Save Changes (updates page)

### 4. Public Page Display

#### URL Structure
- All pages accessible at: `/page/{slug}`
- Examples:
  - `/page/help-center`
  - `/page/contact-us`
  - `/page/faq`
  - `/page/terms-of-service`
  - `/page/privacy-policy`

#### Page Design
- Consistent with Flat Line branding
- Same navigation bar as home page
- Floating orb animations
- Glassmorphism card design
- Responsive layout
- "Back to Home" button

### 5. Footer Integration
The footer component has been updated with working links:

**Support Section**:
- Help Center → `/page/help-center`
- Contact Us → `/page/contact-us`
- FAQ → `/page/faq`

**Legal Section**:
- Terms of Service → `/page/terms-of-service`
- Privacy Policy → `/page/privacy-policy`

### 6. HTML Content Support

Administrators can use the following HTML tags in page content:

- **Headings**: `<h1>`, `<h2>`, `<h3>`
- **Paragraphs**: `<p>`
- **Lists**: `<ul>`, `<ol>`, `<li>`
- **Links**: `<a href="...">`
- **Formatting**: `<strong>`, `<em>`, `<br>`

Example:
```html
<h1>Page Title</h1>
<p>Introduction paragraph with <strong>bold text</strong>.</p>
<h2>Section Heading</h2>
<p>Section content.</p>
<ul>
  <li>List item 1</li>
  <li>List item 2</li>
</ul>
```

## Routes

### Public Routes
```php
Route::get('/page/{slug}', [PageController::class, 'show'])->name('page.show');
```

### Admin Routes (Protected)
```php
Route::middleware(['auth', 'admin'])->prefix('admin')->name('admin.')->group(function () {
    Route::get('/pages', [AdminController::class, 'pages'])->name('pages');
    Route::get('/pages/{id}/edit', [AdminController::class, 'editPage'])->name('pages.edit');
    Route::post('/pages/{id}', [AdminController::class, 'updatePage'])->name('pages.update');
});
```

## Controllers

### PageController
- **show($slug)**: Displays public page by slug

### AdminController (New Methods)
- **pages()**: Lists all pages for admin
- **editPage($id)**: Shows edit form for specific page
- **updatePage(Request $request, $id)**: Updates page content

## Models

### Page Model
- **Fillable**: slug, title, content, meta_data, is_active
- **Casts**: meta_data (array), is_active (boolean)
- **Method**: `getBySlug($slug)` - Retrieves active page by slug

## Database Seeder

### PageSeeder
- Creates/updates all default pages
- Can be run multiple times safely (uses `updateOrCreate`)
- Run with: `php artisan db:seed --class=PageSeeder`

## Usage Instructions

### For Administrators

1. **Access Pages Management**
   - Login to admin dashboard
   - Click "Pages" in the sidebar

2. **Edit a Page**
   - Click "Edit" next to the page you want to modify
   - Update the title and/or content
   - Use HTML tags for formatting
   - Toggle "Page is active" to show/hide page
   - Click "Save Changes"

3. **Preview Changes**
   - Click "Preview Page" to see how it looks
   - Opens in a new tab

4. **View Public Page**
   - Click "View" in the pages list
   - Opens the live page in a new tab

### For Developers

1. **Add New Page**
```php
Page::create([
    'slug' => 'new-page',
    'title' => 'New Page Title',
    'content' => '<h1>Content</h1><p>Text here</p>',
    'is_active' => true,
]);
```

2. **Update Page Programmatically**
```php
$page = Page::where('slug', 'help-center')->first();
$page->update(['content' => 'New content']);
```

3. **Get Page in Controller**
```php
$page = Page::getBySlug('faq');
```

## Files Created/Modified

### Created:
1. `database/migrations/2026_04_02_134632_create_pages_table.php`
2. `database/seeders/PageSeeder.php`
3. `app/Models/Page.php`
4. `app/Http/Controllers/PageController.php`
5. `resources/views/pages/show.blade.php`
6. `resources/views/admin/pages.blade.php`
7. `resources/views/admin/edit-page.blade.php`
8. `resources/views/layouts/admin.blade.php`
9. `CMS_SYSTEM.md` (this file)

### Modified:
1. `app/Http/Controllers/Admin/AdminController.php` - Added 3 methods
2. `routes/web.php` - Added 4 routes
3. `resources/views/components/footer.blade.php` - Updated links
4. `resources/views/admin/dashboard.blade.php` - Added Pages menu item

## Security

- All admin routes protected by `auth` and `admin` middleware
- CSRF protection on all forms
- HTML content is rendered with `{!! !!}` (admin-controlled content)
- Slug cannot be changed to prevent broken links
- Only active pages are visible to public

## Future Enhancements

Potential improvements:
1. Rich text WYSIWYG editor (TinyMCE, CKEditor)
2. Image upload and management
3. Page templates
4. SEO meta tags (title, description, keywords)
5. Page versioning/history
6. Bulk actions (activate/deactivate multiple pages)
7. Page duplication
8. Custom CSS per page
9. Page analytics (views, time on page)
10. Multi-language support

## Testing Checklist

- [x] Pages table created successfully
- [x] Default pages seeded
- [x] Public pages accessible at `/page/{slug}`
- [x] Footer links work correctly
- [x] Admin can view pages list
- [x] Admin can edit page content
- [x] Admin can toggle page active status
- [x] Preview page works
- [x] Save changes updates database
- [x] Inactive pages return 404
- [x] HTML formatting displays correctly
- [x] Responsive design works on mobile
- [x] Navigation consistent across pages

## Support

For questions or issues with the CMS:
1. Check this documentation
2. Review the code comments
3. Test in a development environment first
4. Contact the development team
