# Ref Module

## 1. Pengenalan

Module **Reference** — lookup table untuk menyimpan data master seperti categories, statuses, types yang digunakan oleh modul-modul lain. Guna pattern key-value (cat → code → descr).

## 2. Database

**Table:** `ref`

| Column | Type | Description |
|--------|------|-------------|
| id | bigint (PK) | Primary key |
| cat | string | Kumpulan (contoh: `ARTICLE_CAT`, `LANGUAGE`, `PORTAL`) |
| code | string | Value code (contoh: `ACTIVE`, `BM`, `EN`) |
| descr | string | Description Bahasa Malaysia |
| descr_en | string (nullable) | Description English |
| sort | integer (nullable) | Urutan display |
| parent | string (nullable) | Parent code (hierarki) |
| icon_name | string (nullable) | Nama icon |
| created_by | string (nullable) | Creator username/ID |
| updated_by | string (nullable) | Updater username/ID |
| deleted_at | integer (nullable) | Soft delete |
| timestamps | - | created_at, updated_at |

**Indexes:** cat, code, parent, sort, deleted_at, [cat,sort], [parent,sort]

## 3. Routes

| Method | URI | Permission | Name |
|--------|-----|------------|------|
| GET | `/admin/ref` | `ref.view` | `ref.index` |
| GET | `/admin/ref/create` | `ref.create` | `ref.create` |
| POST | `/admin/ref` | `ref.create` | `ref.store` |
| GET | `/admin/ref/{id}/edit` | `ref.update` | `ref.edit` |
| PUT | `/admin/ref/{id}` | `ref.update` | `ref.update` |
| DELETE | `/admin/ref/{id}` | `ref.delete` | `ref.destroy` |
| POST | `/admin/ref/reorder` | `ref.update` | `ref.reorder` |

## 4. Controller — `RefController`

**Functions:**
- `index()` — List refs, search by cat/code/descr, pagination.
- `create()` — Return create form.
- `store(RefRequest)` — Create ref record.
- `edit($id)` — Return edit form.
- `update(RefRequest, $id)` — Update ref record.
- `destroy($id)` — Delete ref record.

## 5. Model — `Ref`

- Table: `ref`
- Fillable: cat, code, descr, descr_en, sort, parent, icon_name, created_by, updated_by, deleted_at

## 6. Views

- `index.blade.php` — Table: No, Cat, Code, Description (BM), Description (EN), Sort, Actions (edit/delete)
- `create.blade.php` — Form: Cat*, Code*, Description (BM), Description (EN), Sort, Parent, Icon Name
- `edit.blade.php` — Same with pre-filled values
- `show.blade.php` — Detail view

## 7. Cara Guna dalam Module Lain

```php
// Dalam controller — dapatkan options untuk dropdown
$cats = Ref::where('cat', 'ARTICLE_CAT')->orderBy('sort')->pluck('descr', 'code');

// Dalam view
<select name="article_category">
    @foreach ($cats as $code => $descr)
        <option value="{{ $code }}">{{ $descr }}</option>
    @endforeach
</select>
```

Ada `HOW_TO_USE_REF.md` dalam folder view untuk 5 pendekatan berbeza.

## 8. Seeder — `RefDataSeeder`

Seed 78 reference data entries untuk semua categories:
- LANGUAGE (2): BM, EN
- PORTAL (3): portal values
- ARTICLE_CAT (5), ARTICLE_SUBCAT (6), ARTICLE_STATUS (3)
- APPLICATION_CAT (5), APPLICATION_STATUS (3)
- DOWNLOAD_CAT (6), DOWNLOAD_STATUS (3)
- IMAGE_CAT (6), IMAGE_STATUS (3)
- VIDEO_CAT (5), VIDEO_STATUS (3)
- SLIDER_STATUS (3), SLIDER_TYPE (4), SLIDER_DIMENSION (4), SLIDER_URL_TYPE (4)
- PHOTO_STATUS (3), GALLERY_CAT (5), GALLERY_STATUS (3)

## 9. Permissions

| Permission | Description |
|------------|-------------|
| `ref.view` | View ref list & detail |
| `ref.create` | Create ref |
| `ref.update` | Edit ref |
| `ref.delete` | Delete ref |
