getCacheKey($type); return Cache::remember($cacheKey, 3600, function () use ($type) { return $this->modelClass::query()->active()->byType($type)->first(); }); } /** * 템플릿의 변수를 치환하여 제목과 본문을 렌더링합니다. * * @param Model $template 메일 템플릿 모델 * @param array $variables key => value 변수 맵 * @param string|null $locale 로케일 * @return array{subject: string, body: string} 치환된 결과 */ public function renderTemplate(Model $template, array $variables, ?string $locale = null): array { return $template->replaceVariables($variables, $locale); } /** * 템플릿을 시더 기본값으로 복원합니다. * * @param Model $template 복원 대상 템플릿 * @param array $defaultData 기본 데이터 (subject, body, variables) * @return Model 복원된 템플릿 */ public function resetToDefault(Model $template, array $defaultData): Model { $template->update([ 'subject' => $defaultData['subject'], 'body' => $defaultData['body'], 'variables' => $defaultData['variables'] ?? $template->variables, 'is_active' => true, 'is_default' => true, ]); $this->invalidateCache($template->type); return $template->fresh(); } /** * 특정 유형의 캐시를 무효화합니다. * * @param string $type 템플릿 유형 * @return void */ public function invalidateCache(string $type): void { Cache::forget($this->getCacheKey($type)); } /** * 캐시 키를 생성합니다. * * @param string $type 템플릿 유형 * @return string 캐시 키 */ private function getCacheKey(string $type): string { return $this->cachePrefix . $type; } }