resolveSubSectionId($data['section_path'] ?? null); // Generate search_data from content if (!empty($pageData['content'])) { $pageData['search_data'] = $this->generateSearchDataTask->run($pageData['content']); } // Remove fields that should not be set during import unset($pageData['icon']); $page = Page::create($pageData); // Attach SEO if present if (!empty($data['seo'])) { $page->seo()->create([ 'title' => $data['seo']['title'] ?? null, 'description' => $data['seo']['description'] ?? null, ]); } return $page; } private function resolveSubSectionId(?array $sectionPath): ?int { if (empty($sectionPath)) { return null; } $mainSectionSlug = $sectionPath['main_section_slug'] ?? null; $subSectionSlug = $sectionPath['sub_section_slug'] ?? null; if (!$mainSectionSlug || !$subSectionSlug) { return null; } $mainSection = MainSection::where('slug', $mainSectionSlug)->first(); if (!$mainSection) { return null; } $subSection = SubSection::where('main_section_id', $mainSection->id) ->where('slug', $subSectionSlug) ->first(); return $subSection?->id; } }