Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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