Files
larablog/database/seeders/DemoBlogSeeder.php
T
ak 263b98b218 Initial baseline: LaraBlog core with plugin commerce surface.
Captures the current working tree after theme slots, ArticleAccess, and the payment / paid-content plugins so subsequent work has a reviewable git history.
2026-08-12 01:15:38 +08:00

123 lines
3.8 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace Database\Seeders;
use App\Domain\Blog\ContentFormat;
use App\Domain\Plugin\PluginManager;
use App\Models\Article;
use App\Models\Category;
use App\Models\Comment;
use App\Models\Link;
use App\Models\Stylevar;
use App\Models\Tag;
use App\Models\User;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
class DemoBlogSeeder extends Seeder
{
public function run(): void
{
Role::findOrCreate('admin');
Role::findOrCreate('editor');
Role::findOrCreate('member');
$plugins = app(PluginManager::class);
$plugins->syncDiscoveredPlugins();
try {
$plugins->enable('larablog/ai-comment-moderation');
} catch (\Throwable) {
//
}
$admin = User::query()
->where('email', 'admin@larablog.test')
->orWhere('username', 'admin')
->first();
if ($admin === null) {
$admin = User::query()->create([
'email' => 'admin@larablog.test',
'name' => 'Admin',
'username' => 'admin',
'password' => 'password',
]);
} else {
$admin->forceFill([
'email' => 'admin@larablog.test',
'name' => 'Admin',
'username' => 'admin',
'password' => 'password',
])->save();
}
$admin->assignRole('admin');
$category = Category::query()->updateOrCreate(
['id' => 1],
['name' => '随笔', 'display_order' => 0, 'articles_count' => 2]
);
$html = Article::query()->updateOrCreate(
['id' => 1],
[
'category_id' => $category->id,
'user_id' => $admin->id,
'title' => '欢迎使用 LaraBlogHTML 样例)',
'content' => '<p>这是一篇 <strong>HTML</strong> 正文,来自旧站风格。</p><p>你可以在后台切换主题、启停插件,并用 Markdown 继续写作。</p>',
'content_format' => ContentFormat::HTML,
'description' => 'HTML 格式演示',
'published_at' => now()->subDay(),
'visible' => true,
'stick' => true,
]
);
$md = Article::query()->updateOrCreate(
['id' => 2],
[
'category_id' => $category->id,
'user_id' => $admin->id,
'title' => 'Markdown 才是未来',
'content' => "# Hello Markdown\n\n这是 **Markdown** 正文。\n\n- 主题可切换\n- 插件可启停\n- SEO / llms.txt 已就绪\n",
'content_format' => ContentFormat::MARKDOWN,
'description' => 'Markdown 格式演示',
'published_at' => now(),
'visible' => true,
]
);
$tag = Tag::query()->updateOrCreate(['name' => 'larablog'], ['use_count' => 2]);
$tag->articles()->syncWithoutDetaching([$html->id, $md->id]);
Comment::query()->updateOrCreate(
['id' => 1],
[
'article_id' => $md->id,
'author' => '访客',
'content' => '看起来不错',
'moderation_status' => Comment::STATUS_APPROVED,
'published_at' => now(),
]
);
Link::query()->updateOrCreate(
['id' => 1],
[
'name' => 'Laravel',
'url' => 'https://laravel.com',
'note' => 'PHP 框架',
'visible' => true,
]
);
Stylevar::query()->updateOrCreate(
['id' => 1],
[
'title' => 'sidebar_note',
'value' => 'LaraBlog · 现代博客引擎',
'visible' => true,
]
);
}
}