input('record_id'); $type = $request->input('type', 'section'); // header, footer, section // Validate type if (!in_array($type, ['header', 'footer', 'section', 'menu'])) { $type = 'section'; } // Get template and its default data $content = ''; $defaultData = []; if ($recordId) { $template = $this->getTemplate($recordId, $type); if ($template) { $content = $template->html_content ?? ''; $defaultData = $template->default_data ?? []; } } else { // Fallback: eski yöntem (content gönderimi) $content = $request->input('content', ''); } if (empty($content)) { return response('No content to preview', 400); } // Replace placeholders with default data if (!empty($defaultData)) { $content = TemplateService::replacePlaceholders($content, $defaultData); } $html = TemplatePreviewService::getPreviewHtml($content, $type); return response($html) ->header('Content-Type', 'text/html; charset=utf-8'); } /** * Get template object from database by ID * * @param int $id * @param string $type * @return object|null */ private function getTemplate(int $id, string $type): ?object { return match($type) { 'header' => HeaderTemplate::find($id), 'footer' => FooterTemplate::find($id), 'section' => SectionTemplate::find($id), 'menu' => MenuTemplate::find($id), default => null, }; } }