Last active
September 18, 2024 03:25
-
-
Save vluzrmos/6c65412ab66fd5267f89 to your computer and use it in GitHub Desktop.
Laravel - Seeding 100k many rows at 1s
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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