# Events Module CRUD

**Date:** 2026-07-22  
**Developer:** Jeetendra Maharjan  
**Status:** In Progress

---

## Summary
Build Events module in systemadmin with two submodules (Event Categories and Events), including migrations, services, CRUD with modal add/edit (no Livewire).

---

## Changes Made

### 5 — Title autofill for slug / HTML fields
- **File(s) affected:** `resources/views/backend/event-categories/*`, `resources/views/backend/events/*`
- **What was done:** On title keyup in add forms only, auto-fill slug (slugified), html_title, and html_desc; edit forms left untouched
- **Why:** Reduce duplicate typing on create while preserving custom SEO fields when editing

### 1 — Database tables
- **File(s) affected:** `database/migrations/2026_07_22_100001_create_tbl_event_categories_table.php`, `database/migrations/2026_07_22_100002_create_tbl_events_table.php`
- **What was done:** Created `tbl_event_categories` and `tbl_events` with UUID, requested columns; events link to categories via `event_category_id`
- **Why:** Persist event category and event content for admin CRUD

### 2 — Models and services
- **File(s) affected:** `app/Models/EventCategory.php`, `app/Models/Event.php`, `app/Services/Events/EventCategoryService.php`, `app/Services/Events/EventService.php`
- **What was done:** Eloquent models with UUID route keys; services for list/create/update/delete, category status toggle and reorder, cover image upload
- **Why:** Follow Laravel service pattern (business logic out of controllers)

### 3 — Backend controllers, routes, sidebar
- **File(s) affected:** `app/Http/Controllers/Backend/Events/*`, `routes/web.php`, `config/admin-sidebar.php`, `resources/views/components/sidebar/icon.blade.php`
- **What was done:** CRUD controllers (modal redirects for create/edit); routes under systemadmin; Events group with Event Categories + Events children
- **Why:** Expose module in systemadmin navigation with route-permission gating

### 4 — Blade modal CRUD views
- **File(s) affected:** `resources/views/backend/event-categories/*`, `resources/views/backend/events/*`
- **What was done:** Index listings with search; add/edit via Alpine `<x-modal>`; Select2 category select; flatpickr datetime picker; SortableJS reorder for categories
- **Why:** Match Our Children modal CRUD UX without Livewire

---

## Decisions & Notes
- Events require a category (`event_category_id`); category delete is blocked while events exist
- Slug auto-generates from title when left blank
- Category `view_count` is display-only (defaults to 0); not editable in forms
- New categories default to Publish status (same as Our Children)
- Cover images stored on `public` disk under `events/`

---

## Pending / Follow-up
- [ ] Run `php artisan migrate` manually
- [ ] Ensure `php artisan storage:link` if not already linked
- [ ] Open Roles UI (or sync permissions) so new `event-categories.*` / `events.*` permissions attach to roles
- [ ] Optional: wire frontend `/events` page to these tables later
