DatabaseSeeder.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. use Illuminate\Database\Seeder;
  3. use Illuminate\Database\Eloquent\Model;
  4. class DatabaseSeeder extends Seeder
  5. {
  6. /**
  7. * Run the database seeds.
  8. *
  9. * @return void
  10. */
  11. public function run()
  12. {
  13. Model::unguard();
  14. $this->call('UserTableSeeder');
  15. $this->call('PostTableSeeder');
  16. $this->call('TagTableSeeder');
  17. $this->call('PostTagTableSeeder');
  18. Model::reguard();
  19. for ($i = 1; $i < 41; $i++) {
  20. DB::table('editeurs')->insert(['nom' => str_random(rand(8, 22))]);
  21. DB::table('auteurs')->insert(['nom' => str_random(rand(8, 22))]);
  22. }
  23. for ($i = 1; $i < 81; $i++) {
  24. DB::table('livres')->insert([
  25. 'titre' => str_random(rand(8, 22)),
  26. 'editeur_id' => rand(1, 40)
  27. ]);
  28. }
  29. for ($i = 1; $i < 41; $i++) {
  30. $number = rand(2, 8);
  31. for ($j = 1; $j <= $number; $j++) {
  32. DB::table('auteur_livre')->insert([
  33. 'livre_id' => rand(1, 40),
  34. 'auteur_id' => $i
  35. ]);
  36. }
  37. }
  38. }
  39. }