You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
namespace Database\Seeders;
use App\Models\Menu;
use App\Models\Role;
use Illuminate\Database\Seeder;
/**
* 在「已有库」上增量挂载运营管理侧栏(不重复仪表盘/系统管理)。
* 用法php artisan db:seed --class=OperationsMenusSeeder
*/
class OperationsMenusSeeder extends Seeder
{
public function run(): void
{
$role = Role::query()->where('code', 'super_admin')->first();
if (! $role) {
$this->command?->warn('未找到 roles.code=super_admin已跳过。请先运行 DatabaseSeeder / AdminInitSeeder。');
return;
}
$opsRoot = Menu::query()->firstOrCreate(
['path' => '/operations', 'parent_id' => null],
[
'name' => 'Operations',
'title' => '运营管理',
'component' => null,
'icon' => 'Goods',
'sort' => 50,
'visible' => 1,
'keep_alive' => 0,
'permission_code' => null,
'status' => 1,
]
);
$opsChildren = [
['/courses', 'OperationsCourses', '课程管理', 'operations/courses/index', 10, 'Notebook'],
['/activities', 'OperationsActivities', '活动管理', 'operations/activities/index', 20, 'Calendar'],
['/news', 'OperationsNews', '资讯管理', 'operations/news/index', 30, 'Reading'],
];
$ids = [$opsRoot->id];
foreach ($opsChildren as $row) {
$m = Menu::query()->firstOrCreate(
['path' => $row[0], 'parent_id' => $opsRoot->id],
[
'name' => $row[1],
'title' => $row[2],
'component' => $row[3],
'icon' => $row[5],
'sort' => $row[4],
'visible' => 1,
'keep_alive' => 0,
'permission_code' => null,
'status' => 1,
]
);
$ids[] = $m->id;
}
$role->menus()->syncWithoutDetaching($ids);
$this->command?->info('运营管理菜单已挂载到 super_admin增量。');
}
}