Advertisement
Guest User

Untitled

a guest
May 22nd, 2015
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.54 KB | None | 0 0
  1. <?php
  2.     use Illuminate\Database\Seeder;
  3.    
  4.     class TasksTableSeeder extends Seeder
  5.     {
  6.         public function run()
  7.         {
  8.             // Uncomment the below to wipe the table clean before populating
  9.             DB::table('tasks')->delete();
  10.    
  11.             $multiplier = 10;
  12.             $proj_count = ProjectsTableSeeder::$count;
  13.             $faker = Faker\Factory::create('ru_RU');
  14.             $faker->seed(rand(0, $proj_count));
  15.    
  16.             // now, make our data array:
  17.             for ($j = 0; $j < $proj_count; $j++) {
  18.                 $tasks = [];
  19.                 for ($i = 0; $i < $multiplier; $i++) {
  20.                     // $task = array('name' => $faker->name, 'slug' => 'task-'.$i,
  21.                     $task = array(
  22.                         'name' => $faker->name,
  23.                         'slug' => $faker->firstName,
  24.                         'project_id' => rand(1, $proj_count),
  25.                         'completed' => ( bool )rand(0, 1) == 1,
  26.                         'description' => $faker->realText(),
  27.                         'created_at' => new DateTime,
  28.                         'updated_at' => new DateTime
  29.                     );
  30.                     $tasks [] = $task;
  31.                 }
  32.    
  33.                 // Uncomment the below to run the seeder
  34.                 DB::table('tasks')->insert($tasks);
  35.                 echo 'Inserted batch ' . ($j + 1) . ' of ' . $proj_count . ' tasks (' . number_format((($j + 1) * 100 / $proj_count), 2, '.', '') . "%).\r";
  36.             }
  37.             echo "\n";
  38.         }
  39.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement