Update DocumentSeeder to use DocumentService::createDocument

Removes direct Document::create() calls that referenced the dropped
title/content/rendered_html columns. Initial seed now creates the
default-locale translation through the service.
This commit is contained in:
Yutaka Kurosaki
2026-05-10 12:45:06 +09:00
parent c9586612f5
commit 0c13ad1e64
+11 -32
View File
@@ -2,7 +2,6 @@
namespace Database\Seeders; namespace Database\Seeders;
use App\Models\Document;
use Illuminate\Database\Seeder; use Illuminate\Database\Seeder;
class DocumentSeeder extends Seeder class DocumentSeeder extends Seeder
@@ -12,43 +11,23 @@ class DocumentSeeder extends Seeder
*/ */
public function run(): void public function run(): void
{ {
// 既存のドキュメントがある場合はスキップ if (\App\Models\Document::count() > 0) {
if (Document::count() > 0) {
$this->command->info('Documents already exist. Skipping...'); $this->command->info('Documents already exist. Skipping...');
return; return;
} }
$documents = [ $service = app(\App\Services\DocumentService::class);
[ $defaultLocale = config('app.locale', 'en');
'title' => 'Home',
'path' => 'Home.md', $docs = [
'slug' => 'home', ['title' => 'Home', 'content' => $this->getHomeContent()],
'content' => $this->getHomeContent(), ['title' => 'Getting Started', 'content' => $this->getGettingStartedContent()],
], ['title' => 'Markdown Guide', 'content' => $this->getMarkdownGuideContent()],
[
'title' => 'Getting Started',
'path' => 'Getting Started.md',
'slug' => 'getting-started',
'content' => $this->getGettingStartedContent(),
],
[
'title' => 'Markdown Guide',
'path' => 'Markdown Guide.md',
'slug' => 'markdown-guide',
'content' => $this->getMarkdownGuideContent(),
],
]; ];
foreach ($documents as $doc) { foreach ($docs as $d) {
Document::create([ $service->createDocument($d['title'], $d['content'], null, $defaultLocale);
'title' => $doc['title'], $this->command->info("Created: {$d['title']}");
'path' => $doc['path'],
'slug' => $doc['slug'],
'content' => $doc['content'],
'rendered_html' => Document::renderMarkdown($doc['content']),
]);
$this->command->info("Created: {$doc['title']}");
} }
$this->command->info('Initial documents created successfully!'); $this->command->info('Initial documents created successfully!');