Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use Illuminate\Database\Seeder;
- class TasksTableSeeder extends Seeder
- {
- public function run()
- {
- // Uncomment the below to wipe the table clean before populating
- DB::table('tasks')->delete();
- $multiplier = 10;
- $proj_count = ProjectsTableSeeder::$count;
- $faker = Faker\Factory::create('ru_RU');
- $faker->seed(rand(0, $proj_count));
- // now, make our data array:
- for ($j = 0; $j < $proj_count; $j++) {
- $tasks = [];
- for ($i = 0; $i < $multiplier; $i++) {
- // $task = array('name' => $faker->name, 'slug' => 'task-'.$i,
- $task = array(
- 'name' => $faker->name,
- 'slug' => $faker->firstName,
- 'project_id' => rand(1, $proj_count),
- 'completed' => ( bool )rand(0, 1) == 1,
- 'description' => $faker->realText(),
- 'created_at' => new DateTime,
- 'updated_at' => new DateTime
- );
- $tasks [] = $task;
- }
- // Uncomment the below to run the seeder
- DB::table('tasks')->insert($tasks);
- echo 'Inserted batch ' . ($j + 1) . ' of ' . $proj_count . ' tasks (' . number_format((($j + 1) * 100 / $proj_count), 2, '.', '') . "%).\r";
- }
- echo "\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement