get() ->filter(function ($category) { return str_starts_with($category->type, 'SiteContents\\'); }); $totalCategories = $categories->count(); $processed = 0; $created = 0; $skipped = 0; $this->command->info("Found {$totalCategories} SiteContents categories"); foreach ($categories as $category) { $processed++; // Check if a post already exists for this category $postExists = DB::table('posts') ->where('category_id', $category->id) ->exists(); if ($postExists) { // Skip if post already exists for this category $skipped++; $this->command->info("[{$processed}/{$totalCategories}] Skipped {$category->type} (already exists)"); continue; } // Get available locales for this category $categoryTranslations = DB::table('category_translations') ->where('category_id', $category->id) ->get(); // Skip if no translations exist for this category if ($categoryTranslations->isEmpty()) { $skipped++; $this->command->warn("[{$processed}/{$totalCategories}] Skipped {$category->type} (no translations)"); continue; } // Create the post using Eloquent without dispatching events $post = Post::withoutEvents(function () use ($category) { return Post::create([ 'postable_id' => 1, 'postable_type' => 'App\\Models\\Admin', 'category_id' => $category->id, ]); }); $translationCount = 0; // Create post translations for each available locale foreach ($categoryTranslations as $categoryTranslation) { $title = "Placeholder: {$categoryTranslation->name}"; PostTranslation::create([ 'post_id' => $post->id, 'locale' => $categoryTranslation->locale, 'title' => $title, 'excerpt' => null, 'content' => null, 'status' => 1, 'updated_by_user_id' => null, 'from' => null, 'till' => null, ]); $translationCount++; } $created++; $this->command->info("[{$processed}/{$totalCategories}] Created post for {$category->type} ({$translationCount} translations)"); } $this->command->info("\n✓ Seeding completed!"); $this->command->info(" Created: {$created} posts"); $this->command->info(" Skipped: {$skipped} posts"); } }