feat: 分離 AdminUserSeeder 並重構 DatabaseSeeder 支援單獨執行
All checks were successful
Star-Cloud-Deploy-System / deploy-demo (push) Successful in 39s
Star-Cloud-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-12 13:04:59 +08:00
parent a0d107ca79
commit 7db3ee3a05
2 changed files with 43 additions and 7 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Seeder;
/**
* 管理員帳號 Seeder
*
* 執行方式php artisan db:seed --class=AdminUserSeeder
*/
class AdminUserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// 檢查是否已存在 admin 帳號,避免重複建立
$admin = User::where('username', 'admin')->first();
if ($admin) {
$this->command->info('Admin 帳號已存在,跳過建立。');
return;
}
User::create([
'username' => 'admin',
'name' => 'Admin',
'email' => 'admin@star-cloud.com',
'password' => bcrypt('password'),
'role' => 'admin',
]);
$this->command->info('Admin 帳號建立成功!');
}
}