Beispiel #1
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $sqlite = in_array(config('database.default'), ['sqlite', 'testing'], true);
     if (!$sqlite) {
         DB::statement('SET FOREIGN_KEY_CHECKS=0');
     }
     if (is_50() or is_51()) {
         Eloquent::unguard();
     }
     $faker = Faker::create();
     // Seeding authors table
     Author::truncate();
     foreach (range(1, 10) as $index) {
         Author::create(['name' => $faker->userName, 'email' => $faker->safeEmail]);
     }
     $this->command->line("<info>Seeded:</info> authors table");
     // Seeding resources table
     Book::truncate();
     $authorIds = is_50() ? Author::pluck('id') : Author::pluck('id')->toArray();
     foreach (range(1, 100) as $index) {
         Book::create(['title' => $faker->sentence(), 'author_id' => $faker->randomElement($authorIds), 'published_at' => $faker->dateTimeThisCentury, 'description' => $faker->randomElement([$faker->paragraph(), null]), 'out_of_print' => $faker->randomElement([true, false]), 'created_at' => $faker->dateTimeThisYear]);
     }
     if (is_50() or is_51()) {
         Eloquent::regard();
     }
     if (!$sqlite) {
         DB::statement('SET FOREIGN_KEY_CHECKS=1');
     }
     $this->command->line("<info>Seeded:</info> books table");
 }
Beispiel #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $faker = Faker::create();
     // Seeding authors table
     Author::truncate();
     foreach (range(1, 10) as $index) {
         Author::create(['name' => $faker->userName, 'email' => $faker->safeEmail]);
     }
     $this->command->line("<info>Seeded:</info> authors table");
     // Seeding resources table
     Resource::truncate();
     $authorIds = is_51() ? Author::lists('id')->toArray() : Author::lists('id');
     foreach (range(1, 100) as $index) {
         Resource::create(['title' => $faker->sentence(), 'author_id' => $faker->randomElement($authorIds), 'description' => $faker->randomElement([$faker->paragraph(), null]), 'deprecated' => $faker->randomElement([0, 1])]);
     }
     $this->command->line("<info>Seeded:</info> resources table");
 }