SystemMediaTableSeeder.php 653 B

1234567891011121314151617181920212223242526
  1. <?php
  2. use App\Models\SystemMedia;
  3. use App\Models\SystemMediaCategory;
  4. use Illuminate\Database\Seeder;
  5. class SystemMediaTableSeeder extends Seeder
  6. {
  7. /**
  8. * Run the database seeds.
  9. *
  10. * @return void
  11. */
  12. public function run()
  13. {
  14. $media = factory(SystemMedia::class, 20)->create();
  15. $cateIds = SystemMediaCategory::pluck('id')->toArray();
  16. if (!empty($cateIds)) {
  17. $faker = app(Faker\Generator::class);
  18. $media->each(function (SystemMedia $i) use ($cateIds, $faker) {
  19. $i->update(['category_id' => $faker->randomElement($cateIds)]);
  20. });
  21. }
  22. }
  23. }