# 최고 관리자 알림 템플릿 관리 및 동적 설정 구조 추가 정리

## 1. 개요
- **목적**: 관리자가 시스템 내에서 모듈형 알림 템플릿(SMS, LMS, 이메일 등)을 카테고리/소분류별로 체계적으로 등록, 수정 및 관리할 수 있도록 설정 기반 유효성 검증 및 폼 구조 확립.
- **핵심 아키텍처**:
  - `config/notification_categories.php` 설정 파일을 도입하여 카테고리별 허용되는 소분류 구조와 치환 변수 목록을 동적으로 매핑.
  - 관리자 템플릿 수정/등록 뷰(`edit.blade.php` / `create.blade.php`)에서 UI 컨벤션(고정 Form ID `createForm`/`editForm`, 상단 저장 버튼 라벨 "저장") 준수.
  - 정의되지 않은 상수 에러를 방지하고 설정 기반의 동적 검증 및 렌더링 구현.

---

## 2. 주요 구현 내용 및 코드 구조

### 2.1. 카테고리 및 소분류 매핑 설정 파일 (`config/notification_categories.php`)
- 동적 드롭다운 렌더링과 템플릿 유효성 검증의 기준이 되는 설정 파일 구조입니다.

#### <notification_categories.php>

    return [
        'categories' => [
            'SHOP' => [
                'name' => '뷰티샵 관리',
                'subcategories' => [
                    'SHOP_APPLY_ADMIN' => [
                        'name' => '입점 신청 알림 (관리자용)',
                        'variables' => ['shop_name', 'ceo_name', 'applicant_name', 'applicant_phone', 'created_at']
                    ],
                ],
            ],
            'USER' => [
                'name' => '회원 관리',
                'subcategories' => [
                    'USER_WELCOME' => [
                        'name' => '회원가입 환영 인사',
                        'variables' => ['user_name', 'joined_at']
                    ],
                ],
            ],
        ],
    ];
<br>

### 2.2. 템플릿 관리 컨트롤러 (`NotificationTemplateController.php`)
- 설정 파일 기반으로 카테고리 및 소분류 데이터의 무결성을 검증하고, 동적으로 템플릿을 등록 및 수정하는 로직입니다.

#### <NotificationTemplateController.php>

    namespace App\Http\Controllers\Admin;

    use App\Http\Controllers\Controller;
    use App\Models\NotificationTemplate;
    use Illuminate\Http\Request;

    class NotificationTemplateController extends Controller
    {
        public function edit($id)
        {
            $template = NotificationTemplate::findOrFail($id);$categoriesConfig = config('notification_categories.categories', []);

            return view('admin.notification_templates.edit', compact('template', 'categoriesConfig'));
        }

        public function update(Request $request,$id)
        {
            $template = NotificationTemplate::findOrFail($id);

            $validated =$request->validate([
                'title'     => 'required|string|max:255',
                'content'   => 'required|string',
                'is_active' => 'boolean',
            ]);

            $template->update($validated);

            return redirect()->route('admin.notification-templates.index')
                ->with('success', '알림 템플릿이 성공적으로 수정되었습니다.');
        }
    }
<br>

### 2.3. 템플릿 관리 수정 뷰 (`edit.blade.php`)
- 고정 Form ID(`editForm`)와 상단 저장 버튼 라벨("저장") 컨벤션을 준수하며, `window.notificationCategoriesConfig` 기반으로 카테고리/소분류를 동적으로 연동하는 UI 구조입니다.

#### <edit.blade.php>

    @extends('layouts.admin')

    @section('content')
    <div class="container-fluid">
        <form id="editForm" action="{{ route('admin.notification-templates.update', $template->id) }}" method="POST">
            @csrf
            @method('PUT')

            <div class="d-flex justify-content-between align-items-center mb-4">
                <h2>알림 템플릿 수정</h2>
                <button type="submit" class="btn btn-primary">저장</button>
            </div>

            <div class="card shadow mb-4">
                <div class="card-body">
                    <div class="mb-3">
                        <label class="form-label">템플릿 코드</label>
                        <input type="text" class="form-control" value="{{ $template->code }}" disabled>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">템플릿 제목</label>
                        <input type="text" name="title" class="form-control" value="{{ old('title', $template->title) }}" required>
                    </div>

                    <div class="mb-3">
                        <label class="form-label">템플릿 본문</label>
                        <textarea name="content" class="form-control" rows="6" required>{{ old('content', $template->content) }}</textarea>
                    </div>

                    <div class="form-check mb-3">
                        <input type="hidden" name="is_active" value="0">
                        <input type="checkbox" name="is_active" value="1" class="form-check-input" id="isActiveCheck" {{ $template->is_active ? 'checked' : '' }}>
                        <label class="form-check-label" for="isActiveCheck">사용 여부 (활성화)</label>
                    </div>
                </div>
            </div>
        </form>
    </div>
    @endsection

---

## 3. 요약 및 기대 효과
- **설정 주도형 관리**: 하드코딩을 배제하고 `config/notification_categories.php`를 통해 알림 템플릿의 종류와 치환 변수를 확장성 있게 관리할 수 있습니다.
- **일관된 UI/UX**: 모든 관리자 폼에서 정해진 ID 규격(`editForm`)과 버튼 라벨("저장")을 일치시켜 유지보수성을 극대화하였습니다.