Files
star-cloud/database/seeders/AdminUserSeeder.php
sky121113 7db3ee3a05
All checks were successful
Star-Cloud-Deploy-System / deploy-demo (push) Successful in 39s
Star-Cloud-Deploy-System / deploy-production (push) Has been skipped
feat: 分離 AdminUserSeeder 並重構 DatabaseSeeder 支援單獨執行
2026-01-12 13:04:59 +08:00

39 lines
875 B
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\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 帳號建立成功!');
}
}