Skip to content

Instantly share code, notes, and snippets.

@vluzrmos
Last active April 19, 2017 13:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vluzrmos/6c65412ab66fd5267f89 to your computer and use it in GitHub Desktop.
Save vluzrmos/6c65412ab66fd5267f89 to your computer and use it in GitHub Desktop.
Laravel - Seeding 100k many rows at 1s
<?php
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
use App\User;
class DatabaseSeeder extends Seeder {
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Model::unguard();
// User::truncate();
$users = app('db')->table('users');
$senha = bcrypt('1234');
$position = 0;
// inserting 1000 per iteration (=100k)
for($i = 0; $i < 100; $i++){
$list = [];
for($j = 0; $j <= 1000; $j++){
$list[] = [
'name' => 'User '.$position,
'email' => "example.{$position}@example.com",
'password' => $senha
];
$position++;
}
$users->insert($list);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment