# tbl_childrens

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

---

## Summary
Create `tbl_childrens` database table and Eloquent model, plus `/systemadmin` Our Children CRUD module (modal add/edit, list status toggle).

---

## Changes Made

### 1 — Create tbl_childrens migration and Child model
- **File(s) affected:** `database/migrations/2026_07_22_000001_create_tbl_childrens_table.php`, `app/Models/Child.php`
- **What was done:** Added migration for `tbl_childrens` with id, uuid, and requested columns; added `Child` model with UUID auto-generation, route key by uuid, and published scope
- **Why:** Persist children profile data instead of (or in addition to) folder-derived profiles

### 12 — Position field + drag-and-drop reorder
- **File(s) affected:** migration `2026_07_22_000002_add_position_to_tbl_childrens_table.php`, model, `OurChildrenService`, controller, routes, admin index, frontend `ChildrenService`
- **What was done:** Added auto-managed `position` (next max on create); list ordered by position with SortableJS drag handles; AJAX `our-children.reorder`; public `/children` uses same order; no position field on add/edit forms
- **Why:** Requested display order control without manual position input

### 11 — Fix Add prefill + broken Edit modal
- **File(s) affected:** `resources/views/backend/our-children/index.blade.php`, `partials/form.blade.php`
- **What was done:** Stopped list-loop `$child` from leaking into Add form; populate/reset fields via `getElementById` (modal nested Alpine broke `x-ref`)
- **Why:** Add showed last list row; Edit threw before opening modal

### 10 — Clear Add modal; keep Edit prefilled for selected child
- **File(s) affected:** `resources/views/backend/our-children/index.blade.php`, `partials/form.blade.php`
- **What was done:** Stopped Add form from reading shared `old()` input; reset create form + image preview whenever Add opens; Edit still fills from the clicked row
- **Why:** Add was showing previous edit/create values

### 9 — Public /children page uses DB published children
- **File(s) affected:** `app/Services/Children/ChildrenService.php`, `ChildrenController.php`, `resources/views/frontend/children.blade.php`
- **What was done:** Replaced folder/generated profiles with published `tbl_childrens` records (fullname, photo from storage, grade, needs, hobbies, background as story)
- **Why:** Make the public children page dynamic from systemadmin uploads

### 8 — AJAX publish/unpublish toggle
- **File(s) affected:** `OurChildrenController.php`, `resources/views/backend/our-children/index.blade.php`
- **What was done:** Status toggle now PATCHes via fetch and updates the button in-place with a SweetAlert toast; no full page reload
- **Why:** Requested AJAX toggle without refreshing the list

### 7 — Fix broken storage symlink for child photos
- **File(s) affected:** `public/storage` symlink
- **What was done:** Recreated `public/storage` to point at this project’s `storage/app/public` (it previously pointed at `zsystem-laravel`)
- **Why:** Uploaded child images existed on disk but list URLs 404’d / showed missing image

### 6 — Align with `fullname` column + image preview
- **File(s) affected:** model, service, controller, views, migration
- **What was done:** Switched all code from `name` to `fullname` to match the live DB column; added FileReader image preview in add/edit modals
- **Why:** Table uses `fullname` (per original schema); choosing a photo should show a preview before save

### 5 — Modal UI with classic form POST (no Livewire)
- **File(s) affected:** `resources/views/backend/our-children/index.blade.php`, `partials/form.blade.php`, `OurChildrenController.php`; removed dedicated create/edit Blade pages
- **What was done:** Add/Edit open as Alpine/`x-modal` dialogs; forms POST/PUT to existing controller actions and refresh the list page
- **Why:** Keep modal UX without Livewire save path that dropped `name`

### 4 — Remove Livewire; use dedicated create/edit pages
- **File(s) affected:** Livewire modal removed; added `create.blade.php`, `edit.blade.php`, `partials/form.blade.php`; updated controller, routes, index, `Child` model, `OurChildrenService`
- **What was done:** Replaced Livewire modal with standard Blade create/edit pages and form POST/PUT; assign `name` and other fields explicitly on the model before save
- **Why:** Livewire `$name` conflict kept dropping the name column; user requested no Livewire and full page refresh

### 3 — Fix Livewire `name` property conflict
- **File(s) affected:** `app/Livewire/Backend/OurChildren/ChildFormModal.php`, `resources/views/livewire/backend/our-children/child-form-modal.blade.php`
- **What was done:** Renamed form property `name` → `childName` so Livewire no longer drops the child’s name on save
- **Why:** Public `$name` conflicts with Livewire’s component name, causing inserts without the `name` column

### 2 — Our Children backend CRUD module
- **File(s) affected:**
  - `app/Services/OurChildren/OurChildrenService.php`
  - `app/Http/Controllers/Backend/OurChildren/OurChildrenController.php`
  - `app/Livewire/Backend/OurChildren/ChildFormModal.php`
  - `resources/views/livewire/backend/our-children/child-form-modal.blade.php`
  - `resources/views/backend/our-children/index.blade.php`
  - `routes/web.php`
  - `config/admin-sidebar.php`
  - `resources/views/components/sidebar/icon.blade.php`
  - `resources/js/setup-select2.js`
  - `app/Models/Child.php` (image_url accessor)
- **What was done:** Added Our Children module under `/systemadmin/our-children` with search listing, Livewire add/edit modal (no status field), default publish on create, status toggle on list, SweetAlert2 delete, image upload to public disk
- **Why:** Admin CRUD for children profiles as requested

---

## Decisions & Notes
- Table name kept as `tbl_childrens` per request
- Status values normalized to lowercase `publish` / `unpublish` for DB consistency
- Gender stored as enum: `Male`, `Female`, `Other`
- Add/edit use Livewire modal (no status fields); new records default to `publish`
- Status toggled from list page only
- Route prefix/name: `our-children` (avoids clash with public `children` route)
- Permissions sync from named routes when Roles create/edit (or Super Admin sync) runs

---

## Pending / Follow-up
- [x] User to run `php artisan migrate` manually (if not already)
- [x] Ensure `php artisan storage:link` points at this project’s `storage/app/public`
- [ ] Open Roles create/edit (or re-seed Super Admin) so `our-children.*` permissions sync
- [x] Wire frontend Children page to DB
