refactor: kb & station & terminal
This commit is contained in:
@@ -4,7 +4,7 @@ namespace Database\Seeders;
|
||||
|
||||
use App\Models\Guide;
|
||||
use App\Models\GuidePage;
|
||||
use App\Models\Terminal;
|
||||
use App\Models\Station;
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
@@ -20,7 +20,7 @@ class GuideSeeder extends Seeder
|
||||
$this->command->info('开始创建操作指引数据...');
|
||||
|
||||
$admin = User::where('email', 'admin@example.com')->first();
|
||||
$terminals = Terminal::all();
|
||||
$stations = Station::all();
|
||||
|
||||
// 1. 如何用光(带分支)
|
||||
$guide1 = $this->createHowToUseBeamGuide($admin);
|
||||
@@ -31,20 +31,17 @@ class GuideSeeder extends Seeder
|
||||
// 3. 漏水报警处理
|
||||
$guide3 = $this->createWaterLeakAlarmGuide($admin);
|
||||
|
||||
// 将所有指引关联到所有终端
|
||||
$this->command->info('关联指引到所有终端...');
|
||||
foreach ($terminals as $terminal) {
|
||||
$terminal->guides()->attach([
|
||||
$guide1->id => ['priority' => 1],
|
||||
$guide2->id => ['priority' => 2],
|
||||
$guide3->id => ['priority' => 3],
|
||||
]);
|
||||
}
|
||||
// 将指引关联到所有线站(非全局,关联所有线站 = 各线站均可见)
|
||||
$this->command->info('关联指引到所有线站...');
|
||||
$stationIds = $stations->pluck('id')->toArray();
|
||||
$guide1->stations()->attach($stationIds);
|
||||
$guide2->stations()->attach($stationIds);
|
||||
$guide3->stations()->attach($stationIds);
|
||||
|
||||
$this->command->info('操作指引数据创建完成!');
|
||||
$this->command->info(' - 指引数量: ' . Guide::count());
|
||||
$this->command->info(' - 指引页面数量: ' . GuidePage::count());
|
||||
$this->command->info(' - 关联终端数量: ' . $terminals->count());
|
||||
$this->command->info(' - 关联线站数量: ' . $stations->count());
|
||||
}
|
||||
|
||||
private function createHowToUseBeamGuide(User $admin): Guide
|
||||
|
||||
Reference in New Issue
Block a user