适配游客组能使用多个储存的特性

This commit is contained in:
Wisp X
2022-03-01 11:39:51 +08:00
parent 60a7d0a87d
commit 843abacdef
25 changed files with 240 additions and 230 deletions

View File

@@ -21,6 +21,7 @@ return new class extends Migration
$table->id();
$table->string('name', 64)->comment('角色组名称');
$table->boolean('is_default')->default(false)->comment('是否默认');
$table->boolean('is_guest')->default(false)->comment('是否为游客组');
$table->json('configs')->comment('组配置');
$table->timestamps();
});

View File

@@ -2,6 +2,9 @@
namespace Database\Seeders;
use App\Enums\ConfigKey;
use App\Enums\StrategyKey;
use App\Models\Group;
use Illuminate\Database\Seeder;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
@@ -16,7 +19,9 @@ class InstallSeeder extends Seeder
public function run()
{
$date = Carbon::now()->format('Y-m-d H:i:s');
$array = collect(config('convention.app'))->transform(function ($value, $key) use ($date) {
$array = collect(config('convention.app'))->except([
ConfigKey::Group,
])->transform(function ($value, $key) use ($date) {
return [
'name' => $key,
'value' => is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value,
@@ -24,6 +29,23 @@ class InstallSeeder extends Seeder
'created_at' => $date,
];
})->values()->toArray();
DB::table('configs')->insert($array);
DB::transaction(function () use ($array) {
DB::table('configs')->insert($array);
// 创建默认组和默认策略
/** @var Group $group */
$group = Group::query()->create([
'name' => '系统默认组&游客组',
'is_default' => true,
'is_guest' => true,
'configs' => config('convention.app.group'),
]);
// 创建默认策略
$group->strategies()->create([
'key' => StrategyKey::Local,
'name' => '默认本地策略',
'intro' => '系统默认的本地策略',
'configs' => config('filesystems.disks.uploads'),
]);
});
}
}