VueRoutersTableSeeder.php 873 B

12345678910111213141516171819202122232425262728293031323334
  1. <?php
  2. use App\Models\VueRouter;
  3. use Illuminate\Database\Seeder;
  4. class VueRoutersTableSeeder extends Seeder
  5. {
  6. public function run()
  7. {
  8. VueRouter::truncate();
  9. // 暂时弄一个写死的首页,方便前端显示
  10. factory(VueRouter::class)->create([
  11. 'path' => '/index',
  12. 'title' => '首页',
  13. 'order' => 0,
  14. ]);
  15. $vueRouters = factory(VueRouter::class, 9)->make([
  16. 'created_at' => now(),
  17. 'updated_at' => now(),
  18. ])->toArray();
  19. // 三级嵌套菜单
  20. foreach ($vueRouters as $i => &$router) {
  21. if ($i < 3) {
  22. $parentId = 0;
  23. } else {
  24. $parentId = $i - 1;
  25. }
  26. $router['parent_id'] = $parentId;
  27. }
  28. unset($router);
  29. VueRouter::insert($vueRouters);
  30. }
  31. }