tenantId(); return SectionTemplate::where('tenant_id', $tenantId) ->orderBy('created_at', 'desc') ->get(); } /** * 섹션 템플릿 생성 */ public function store(array $data): SectionTemplate { $tenantId = $this->tenantId(); $userId = $this->apiUserId(); $template = SectionTemplate::create([ 'tenant_id' => $tenantId, 'title' => $data['title'], 'type' => $data['type'], 'description' => $data['description'] ?? null, 'is_default' => $data['is_default'] ?? false, 'created_by' => $userId, ]); return $template; } /** * 섹션 템플릿 수정 */ public function update(int $id, array $data): SectionTemplate { $tenantId = $this->tenantId(); $userId = $this->apiUserId(); $template = SectionTemplate::where('tenant_id', $tenantId) ->where('id', $id) ->first(); if (! $template) { throw new NotFoundHttpException(__('error.not_found')); } $template->update([ 'title' => $data['title'] ?? $template->title, 'type' => $data['type'] ?? $template->type, 'description' => $data['description'] ?? $template->description, 'is_default' => $data['is_default'] ?? $template->is_default, 'updated_by' => $userId, ]); return $template->fresh(); } /** * 섹션 템플릿 삭제 */ public function destroy(int $id): void { $tenantId = $this->tenantId(); $userId = $this->apiUserId(); $template = SectionTemplate::where('tenant_id', $tenantId) ->where('id', $id) ->first(); if (! $template) { throw new NotFoundHttpException(__('error.not_found')); } $template->update(['deleted_by' => $userId]); $template->delete(); } }