# Blog Management Module Usage Instructions

> The `feat/admin-sub/blogs` branch introduces a fully-featured Blog Management module. It is built on top of the secure `feat/admin` and `base` branches, utilizing the existing component library, authentication flow, and robust UI architecture to deliver a seamless content management experience.

---

## Table of Contents

1. [Module Overview](#1-module-overview)
2. [What You Inherit](#2-what-you-inherit)
3. [Deep Dive: Features & Functionality](#3-deep-dive-features--functionality)
4. [File Paths & Architecture](#4-file-paths--architecture)
5. [Step-by-Step Usage Guide](#5-step-by-step-usage-guide)

---

## 1. Module Overview

This branch establishes the Blog Management area within the Admin Portal. It provides administrators with the ability to create, read, update, delete, and manage blog posts. The module includes support for rich text editing, featured images, SEO metadata, and soft deletion (Archived blogs). 

---

## 2. What You Inherit

By merging with the **Base** and **Admin** branches, this feature inherits:
- **Base Components:** All `<x-common.*>`, `<x-forms.*>`, and `<x-buttons.*>` Blade components used to style the table and forms.
- **Admin Security:** The `auth:admin` middleware ensures only logged-in administrators can access blog management routes.
- **Utility Controllers:** Built-in tools like `TinyMceController` for handling rich-text image uploads directly from the editor.
- **AJAX Architecture:** A seamless user experience powered by Alpine.js and Server-Side Datatables (`<x-common.table-server>`).

---

## 3. Deep Dive: Features & Functionality

This branch introduces a comprehensive set of features specific to content management:

- **Complete CRUD Operations:** 
  Create, Read, Update, and Delete capabilities for blog posts with server-side validation.
- **Rich Text Editor Integration:** 
  Utilizes TinyMCE for creating rich HTML content, seamlessly integrated into the application layout.
- **Image Uploads & Management:** 
  Handles image uploads with preview functionality, replacing old images securely.
- **Interactive Status Management:**
  Quickly change the status of blogs (Published, Unpublished, Draft) directly from the table using interactive Alpine.js dropdowns.
- **Soft Deletion & Archiving:**
  Deleted blogs are moved to an "Archived" tab rather than permanently deleted immediately. 
- **Bulk Actions:** 
  Perform bulk deletion on active blogs and bulk restore or bulk permanent delete on archived blogs.
- **SEO Optimization Support:** 
  Includes fields for Meta Title, Meta Description, and Meta Keywords.
- **Localized Messaging:** 
  All UI text, table headers, and success/error messages are fully localized using Laravel's translation system (`lang/en/pages/admin/blog.php`).

---

## 4. File Paths & Architecture

Here are the key files introduced or modified in this branch:

### Controllers & Services (`app/Http/Controllers/Admin/Blog/`, `app/Services/Admin/`)
- **`BlogController.php`**: The primary controller handling the view rendering and AJAX data responses.
- **`BlogService.php`**: Encapsulates the business logic, database transactions, image uploading logic, and status updates.
- **`BlogRequest.php`**: Form request class handling all input validation rules and custom messages.

### Models & Migrations (`app/Models/`, `database/migrations/`)
- **`Blog.php`**: The Eloquent model with soft-delete capabilities, mutators/accessors, and status constant definitions.
- **`*_create_blogs_table.php`**: Database migration defining the table schema, including SEO and status fields.

### Views (`resources/views/pages/admin/blog/`)
- **`index.blade.php`**: The primary view displaying the active blogs data table.
- **`archived.blade.php`**: The view displaying soft-deleted blogs and their specific actions (Restore/Permanent Delete).
- **`form.blade.php`**: The shared form view used for both Creating and Editing blog posts.
- **`partials/table.blade.php`**: The server-side table partial for AJAX rendering.

### JavaScript (`resources/js/admin/`)
- **`blog.js`**: Contains the Alpine.js component logic for handling datatables, status updates, and bulk actions.
- **`blog-form.js`**: Manages form-specific interactions like image previews.

---

## 5. Step-by-Step Usage Guide

### 1. Database Setup
Ensure your database has the new `blogs` table. Run your migrations:
```bash
php artisan migrate
```

### 2. Accessing the Module
- Log into the Admin Portal (`/behindthescreen`).
- In the sidebar navigation, locate and click on **Blogs** under the CMS or Content section.

### 3. Managing Blogs
- **Creating a Blog:** Click "Add New Blog", fill in the title, content (via TinyMCE editor), select a featured image, define SEO tags, and save.
- **Status Updates:** On the `index` view, use the status dropdown in the table row to immediately toggle a blog between Publish, Unpublish, and Draft.
- **Archiving/Deleting:** Use the delete action on a record or select multiple records for Bulk Deletion. These records will move to the "Archived" tab.
- **Restoring Data:** Navigate to the "Archived" tab to review soft-deleted blogs. You can select them to restore or permanently remove them from the database.
