# Phase 15: Admin Content Operations Upgrade

## Date
- 2026-04-18

## Scope
- Improved admin-only management for categories, instructors, and course programs.
- Expanded course/lecture schema to support a Udemy-style admin builder without breaking the existing student/instructor experience.
- Added admin CRUD flows for sections and lectures inside the course builder.

## What Was Implemented
1. Category management refresh
   - Preserved existing category CRUD.
   - Added category search and improved admin presentation for parent/subcategory visibility.
2. Instructor management
   - Added a dedicated `/admin/instructors` CRUD module.
   - Instructors now support bio, avatar/profile image, status, and JSON-based social links.
   - Instructor accounts are always aligned to `role = instructor` and `user_type = instructor`.
   - Demo/admin account seeding now also ensures `admin@cepi.pk` stays aligned to `role = admin` and `user_type = admin`, preventing `/dashboard` vs `/admin/*` access mismatch.
3. Course management upgrade
   - Added richer course fields:
     - `promo_video_url`
     - `discount_price`
     - `total_duration`
     - `total_lectures`
     - `rating`
     - `total_students`
   - Admin course create/edit screens now support these fields directly.
   - Course aggregate fields are recalculated from lectures, enrollments, and reviews through model logic.
4. Section and lecture builder
   - Reused existing `course_modules` and `lessons` tables as:
     - `Sections` = `course_modules`
     - `Lectures` = `lessons`
   - Completed admin CRUD for:
     - create/update/delete sections
     - create/update/delete lectures
   - Added richer lecture fields:
     - `video_url`
     - `article_content`
     - `video_provider`
     - `video_length`
     - `resolution`
     - `subtitles`
     - `thumbnail`
     - `quiz_data`
5. Supporting schema for future course operations
   - Added `course_reviews` table for rating/review storage.
   - Added `quizzes` table for structured lecture quiz records.
   - Existing `enrollments` and `lesson_progress` tables remain the source of truth for purchases and progress tracking.
6. Admin shell refresh
   - Upgraded the base admin layout into a proper operations sidebar with direct access to users, instructors, categories, courses, enrollments, payments, and settings.

## Files Added
- `app/Http/Controllers/Admin/InstructorController.php`
- `app/Models/CourseReview.php`
- `app/Models/Quiz.php`
- `database/migrations/2026_04_18_120000_expand_admin_course_management_tables.php`
- `resources/views/admin/instructors/index.blade.php`
- `resources/views/admin/instructors/create.blade.php`
- `resources/views/admin/instructors/edit.blade.php`
- `docs/dev/15-admin-content-operations-upgrade.md`

## Files Updated
- `routes/web.php`
- `app/Models/User.php`
- `app/Models/Course.php`
- `app/Models/Lesson.php`
- `app/Http/Controllers/Admin/UserController.php`
- `app/Http/Controllers/Admin/CategoryController.php`
- `app/Http/Controllers/Admin/CourseController.php`
- `app/Http/Controllers/Admin/CourseModuleController.php`
- `app/Http/Controllers/Admin/LessonController.php`
- `resources/views/layouts/admin.blade.php`
- `resources/views/admin/categories/index.blade.php`
- `resources/views/admin/categories/create.blade.php`
- `resources/views/admin/categories/edit.blade.php`
- `resources/views/admin/users/index.blade.php`
- `resources/views/admin/users/create.blade.php`
- `resources/views/admin/users/edit.blade.php`
- `resources/views/admin/courses/index.blade.php`
- `resources/views/admin/courses/create.blade.php`
- `resources/views/admin/courses/edit.blade.php`

## Route Notes
- Added:
  - `/admin/instructors`
- Tightened admin nested content routes to only the actions used by the course builder:
  - `admin.modules.store`
  - `admin.modules.update`
  - `admin.modules.destroy`
  - `admin.lessons.store`
  - `admin.lessons.update`
  - `admin.lessons.destroy`

## Assumptions
- Existing `course_modules` and `lessons` remain the canonical content tables; the admin UI now presents them as sections and lectures rather than introducing a parallel structure.
- Video metadata was folded into the lecture record for faster admin implementation, while `quizzes` and `course_reviews` were introduced as standalone supporting tables for future expansion.
