Files
star-erp/database/seeders/TenantDatabaseSeeder.php
2026-02-02 13:16:06 +08:00

49 lines
1.2 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 Illuminate\Database\Seeder;
use App\Modules\Core\Models\User;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
/**
* 租戶資料庫專用 Seeder
*
* 建立新租戶時會自動執行此 Seeder負責
* 1. 建立預設的超級管理員帳號
* 2. 設定權限與角色
*/
class TenantDatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*/
public function run(): void
{
// 建立預設管理員帳號
$admin = User::firstOrCreate(
['username' => 'admin'],
[
'name' => '系統管理員',
'email' => 'admin@example.com',
'password' => 'password',
]
);
// 呼叫權限 Seeder 設定權限與角色
$this->call(PermissionSeeder::class);
// 初始化基本單位資料
$this->call(UnitSeeder::class);
// 初始化預設商品分類
$this->call(CategorySeeder::class);
// 確保 admin 擁有 super-admin 角色
if (!$admin->hasRole('super-admin')) {
$admin->assignRole('super-admin');
}
}
}