Files
star-cloud/database/seeders/AdminUserSeeder.php
sky121113 d3684385b2
All checks were successful
Star-Cloud-Deploy-System / deploy-demo (push) Successful in 44s
Star-Cloud-Deploy-System / deploy-production (push) Has been skipped
fix: 修正 AdminUserSeeder 欄位結構與資料庫一致
2026-01-12 13:08:00 +08:00

46 lines
1.1 KiB
PHP
Raw Permalink 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;
use Illuminate\Support\Facades\Hash;
/**
* 管理員帳號 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 帳號已存在,執行更新密碼與資料。');
$admin->update([
'name' => 'Admin',
'email' => 'admin@star-cloud.com',
'password' => Hash::make('password'),
'role' => 'admin',
]);
return;
}
User::create([
'username' => 'admin',
'name' => 'Admin',
'email' => 'admin@star-cloud.com',
'password' => Hash::make('password'),
'role' => 'admin',
]);
$this->command->info('Admin 帳號建立成功!');
}
}