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:
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use App\Models\Document;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class DocumentSeeder extends Seeder
|
||||
@@ -12,43 +11,23 @@ class DocumentSeeder extends Seeder
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
// 既存のドキュメントがある場合はスキップ
|
||||
if (Document::count() > 0) {
|
||||
if (\App\Models\Document::count() > 0) {
|
||||
$this->command->info('Documents already exist. Skipping...');
|
||||
return;
|
||||
}
|
||||
|
||||
$documents = [
|
||||
[
|
||||
'title' => 'Home',
|
||||
'path' => 'Home.md',
|
||||
'slug' => 'home',
|
||||
'content' => $this->getHomeContent(),
|
||||
],
|
||||
[
|
||||
'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(),
|
||||
],
|
||||
$service = app(\App\Services\DocumentService::class);
|
||||
$defaultLocale = config('app.locale', 'en');
|
||||
|
||||
$docs = [
|
||||
['title' => 'Home', 'content' => $this->getHomeContent()],
|
||||
['title' => 'Getting Started', 'content' => $this->getGettingStartedContent()],
|
||||
['title' => 'Markdown Guide', 'content' => $this->getMarkdownGuideContent()],
|
||||
];
|
||||
|
||||
foreach ($documents as $doc) {
|
||||
Document::create([
|
||||
'title' => $doc['title'],
|
||||
'path' => $doc['path'],
|
||||
'slug' => $doc['slug'],
|
||||
'content' => $doc['content'],
|
||||
'rendered_html' => Document::renderMarkdown($doc['content']),
|
||||
]);
|
||||
|
||||
$this->command->info("Created: {$doc['title']}");
|
||||
foreach ($docs as $d) {
|
||||
$service->createDocument($d['title'], $d['content'], null, $defaultLocale);
|
||||
$this->command->info("Created: {$d['title']}");
|
||||
}
|
||||
|
||||
$this->command->info('Initial documents created successfully!');
|
||||
|
||||
Reference in New Issue
Block a user