fix(seeder): 修复 DatabaseSeeder 和 SopTemplateSeeder 的问题
- DatabaseSeeder 添加 PermissionSeeder 调用,确保权限系统正确初始化 - 为所有演示用户分配相应角色(super-admin, admin, user) - 修复 SopTemplateSeeder 中被截断的正则表达式 - 更新测试账号信息,显示用户角色 - 验证所有 seeder 正常执行,数据创建成功
This commit is contained in:
@@ -20,42 +20,52 @@ class DatabaseSeeder extends Seeder
|
||||
{
|
||||
$this->command->info('开始生成演示数据...');
|
||||
|
||||
// 0. 创建系统设置
|
||||
// 0. 创建权限和角色(必须最先执行)
|
||||
$this->call(PermissionSeeder::class);
|
||||
|
||||
// 1. 创建系统设置
|
||||
$this->call(SystemSettingSeeder::class);
|
||||
|
||||
// 1. 创建管理员用户
|
||||
// 2. 创建管理员用户
|
||||
$this->command->info('创建管理员用户...');
|
||||
$admin = User::factory()->create([
|
||||
'name' => '系统管理员',
|
||||
'email' => 'admin@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
|
||||
// 为管理员分配 super-admin 角色
|
||||
$admin->assignRole('super-admin');
|
||||
|
||||
// 2. 创建普通用户
|
||||
// 3. 创建普通用户
|
||||
$this->command->info('创建普通用户...');
|
||||
$user1 = User::factory()->create([
|
||||
'name' => '张三',
|
||||
'email' => 'zhangsan@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
$user1->assignRole('user');
|
||||
|
||||
$user2 = User::factory()->create([
|
||||
'name' => '李四',
|
||||
'email' => 'lisi@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
$user2->assignRole('user');
|
||||
|
||||
$user3 = User::factory()->create([
|
||||
'name' => '王五',
|
||||
'email' => 'wangwu@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
$user3->assignRole('admin');
|
||||
|
||||
$user4 = User::factory()->create([
|
||||
'name' => '赵六',
|
||||
'email' => 'zhaoliu@example.com',
|
||||
'password' => Hash::make('password'),
|
||||
]);
|
||||
$user4->assignRole('user');
|
||||
|
||||
// 3. 创建分组
|
||||
$this->command->info('创建分组...');
|
||||
@@ -219,10 +229,10 @@ class DatabaseSeeder extends Seeder
|
||||
$this->command->info(' - 专用文档: ' . Document::dedicated()->count());
|
||||
$this->command->newLine();
|
||||
$this->command->info('=== 测试账号信息 ===');
|
||||
$this->command->info('管理员: admin@example.com / password');
|
||||
$this->command->info('张三(技术部): zhangsan@example.com / password');
|
||||
$this->command->info('李四(技术部): lisi@example.com / password');
|
||||
$this->command->info('王五(市场部): wangwu@example.com / password');
|
||||
$this->command->info('赵六(人力资源部): zhaoliu@example.com / password');
|
||||
$this->command->info('超级管理员: admin@example.com / password (super-admin)');
|
||||
$this->command->info('张三(技术部): zhangsan@example.com / password (user)');
|
||||
$this->command->info('李四(技术部): lisi@example.com / password (user)');
|
||||
$this->command->info('王五(市场部): wangwu@example.com / password (admin)');
|
||||
$this->command->info('赵六(人力资源部): zhaoliu@example.com / password (user)');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user