SystemMediaCategoriesTableSeeder.php 564 B

12345678910111213141516171819202122
  1. <?php
  2. use App\Models\SystemMediaCategory;
  3. use Illuminate\Database\Seeder;
  4. class SystemMediaCategoriesTableSeeder extends Seeder
  5. {
  6. /**
  7. * Run the database seeds.
  8. *
  9. * @return void
  10. */
  11. public function run()
  12. {
  13. // 5 个一级分类
  14. $cates = factory(SystemMediaCategory::class, 5)->create();
  15. // 每个一级分类下,两个二级分类
  16. $cates->each(function (SystemMediaCategory $i) {
  17. $i->children()->createMany(factory(SystemMediaCategory::class, 2)->make()->toArray());
  18. });
  19. }
  20. }